Step 4

In this section:

The next thing we need is a child window in order to present the results of the factorising process. factor4.for includes the code for such a window but we shall leave out the code that calculates the results until the end. Here is the text of factor4.for:

 3   PROGRAM factor4
 5   INCLUDE <windows.ins>
 6   EXTERNAL factoriser
 7   INTEGER ans,number
 8   CHARACTER*50 str
 9   COMMON number,str
10   number=1
11   str=' '
12   ans=winio@('%ca[Number Factoriser]&')
13   ans=winio@('%il&',1,2147483647)
14   ans=winio@('Number to be factorised: %rd&',number)
15   ans=winio@('%ta%`^bt[Fac&torise]&',factoriser)
16   ans=winio@('%2nl%ob%42st%cb',str)
17   END
19   INTEGER FUNCTION factoriser()
20   INTEGER number
21   CHARACTER*50 str
22   COMMON number,str
23   WRITE(str,*)number
24   CALL window_update@(str)
25   factoriser=1
26   END

Lines 8, 9, 11, 16 and 19 to 26 have been added and as before an "&" character has been placed at the end of the format string on line 15.

When the program is compiled the result looks like this:

At the current state of development, when you click on the "Factorise" button, the number that has been entered is simply copied to the new child window.

The allocation of the variable number to a common block in lines 9, and 22, provides a method for passing this variable to the factoriser function. You will recall that call-back functions like factoriser do not have any arguments. Line 23 stores the value of number as a character string in str. str is also held in common because it is used for output on line 16:


On line 16, %2nl provides two line feeds so that the child window that follows is placed below the existing controls.

The %ob (Open Box) format code is used to open a box at the current position. It automatically marks the position of the top left-hand corner of a box that will be drawn when a corresponding %cb (close box) is encountered. %cb automatically marks the position of the bottom right-hand corner of the box. The box is simply provided as a border. The enclosed area has no special attributes. In the present case the box is used to enclose a string that is produced by the %st format. The string is located in str and the width of the associated area is 42 characters. However, the standard width of a character in this context will be the maximum width of all the characters of the proportionally spaced font.

Finally, line 24 has the effect of updating the string on the screen in order to reflect a change in the contents of str.



Copyright © 1999-2021 Silverfrost Limited