Step 2

In this section:

Here is the text of factor2.for.

 3   PROGRAM factor2
 5   INCLUDE <windows.ins>
 6   INTEGER ans,number
 7   number=1
 8   ans=winio@('%ca[Number Factoriser]&')
 9   ans=winio@('%il&',1,2147483647)
10   ans=winio@('Number to be factorised: %rd',number)
11   END

Note that number has been added to line 6 and & has been inserted towards the end of line 8. Lines 7, 9 and 10 have also been included.

If you compile, link and run this program the output looks like this.

A flashing text cursor appears in the inner box and the user is able to enter any integer in the range from 1 to 2147483647. As before Alt-F4 terminates the application.

The "&" character in line 8 is simply a device to allow the description of the format window to continue in the next call to winio@ (on line 9 in this case). Using this device avoids long format strings with long lists of associated arguments.

Line 9 contains the format code %il (Integer Limit). This specifies the integer limit for the input on line 10. %il takes two (INTEGER) values that are provided as extra arguments to winio@. The lower limit is 1 and the upper limit (2147483647) is the largest possible 32 bit integer. The "&" character allows continuation in the next winio@ call.

In line 9 the format string begins with some text that comes before the next format code which is %rd (Edit Integer). This text is simply copied to the window. The text includes the space before %rd. Without the %il, the user would be able to enter negative or zero values which would not make sense in this application.

The %rd format code is used for user integer input. It creates an edit box and displays the value of the INTEGER variable (in this case number) that is provided as the next argument of winio@. The initial value of number in line 7 has been chosen to be in the permitted range. Users will find that they are only able to type in integers in this range. Each time a single digit is typed, number is updated so that it always holds the value that is visible on the screen.

Now we are ready for step 3.



Copyright © 1999-2021 Silverfrost Limited