Silverfrost Logo About Us | Contact Us
 

Step 3

Now that we have a window and the user is able to input an integer, the next stage is to add a button to initiate the factorising process. factor3.for includes code for such a button. Here is the text:

 1   WINAPP 'CWP_ICO.RC'
 2   
 3   PROGRAM factor3
 4   IMPLICIT NONE
 5   INCLUDE <windows.ins>
 6   EXTERNAL factoriser
 7   INTEGER ans,number
 8   number=1
 9   ans=winio@('%ca[Number Factoriser]&')
10   ans=winio@('%il&',1,2147483647)
11   ans=winio@('Number to be factorised: %rd&',number)
12   ans=winio@('%ta%`^bt[Fac&torise]',factoriser)
13   END
14
15   INTEGER FUNCTION factoriser()
16   factoriser=1
17   END

Note that lines 6, 12 and 15 to 17 have been added to factor2.for. Also an "&" character has been inserted after %rd on line 11. We need to look at line 12 in detail. The other new lines simply declare an external function which for the moment merely returns the value 1.

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

But at the moment nothing happens when you click on the button.

Line 12 of the program uses the format code %bt to provide the button. The text on the button is given as a standard character string (in square brackets) The "&" character in "Fac&torise" has the visual effect of producing an underscore on the next letter ('t' in this case). The result is that 't' on the keyboard can be used as an alternative to clicking on the button when used in combination with the Alt key i.e. Alt-T.

Note that two special characters, a grave accent (`) and a caret character (^), have been included after the % sign. These are two out of a set of four characters called format modifiers (the others are the tilde (~) and the question mark (?)). As it happens, all four modifiers may be used with %bt, but the number of modifiers that a format code can take and the effect each modifier has varies from one format code to another.

In the present case of the button format %bt, the grave accent means that this button is the default button. The default button has a slightly different appearance and is the one that is selected when the Enter key is pressed.

The caret means that a call-back function (called factoriser in this case) is provided as the next argument of winio@. This is the function that is to be called when the user clicks on the button. Call-back functions that are used with winio@ must have no arguments and must return an integer value. It is advisable that this function be declared EXTERNAL.

Finally we note that a tab (represented by %ta) has been placed before the %bt format code. This has been used to separate the button from the text before it. Alternatively, you could simply use spaces.

A call-back function must return one of the following values:

0 or negative

Closes the format window.

1

The window remains open and the whole window is refreshed to allow any changes to be displayed.

2

The window is left open with no refresh. If anything needs to be updated before the call-back returns, a call to window_update@ is used to refresh individual components.

3

Used only with %mg.

 

 

Copyright © 1999-2017 Silverfrost Limited