Silverfrost Logo About Us | Contact Us
 

Advanced use of format windows

It is convenient at this point to mention a few advanced approaches to ClearWin+ programming. If you are still unfamiliar with how to program with winio@, it would be better to skip this section for the moment.

There are three ways in which the usage of winio@ can be varied under program control. First, you can use winio@ statements within flow control constructs such as DO and IF constructs. Here is a simple example.

      WINAPP
       INTEGER, n,i,winio@
       COMMON n
       EXTERNAL cb_func
       i=winio@('Number of lines: %4rd&',n)
       i=winio@('%2nl%cn%^tt[Show]',cb_func)
      END
c-------------------------------------------
      INTEGER function cb_func()
       INTEGER n,i,j,winio@
       COMMON n
       DO j=1,n
         i=winio@('Line %wd%nl&',j)
       ENDDO
       i=winio@(' ')
       cb_func=1
      END

The first dialog box allows you to enter a number. Clicking on the button then produces another dialog box with the given number of lines of output. Notice that the format string within the DO loop is terminated by an ampersand (&) to allow the description of the dialog box to continue on the next loop. The final call to winio@, acts as a terminator. It contains only a format string with a single space character. The same idea can be used with other flow control constructs containing calls to winio@.

A second method for varying the use of winio@ under program control involves changes to the format string. The next example illustrates the idea.

      WINAPP
       INTEGER n,i,winio@
       COMMON n
       EXTERNAL cb_func
       n=1
       i=winio@('Format 1 or 2: %4rd&',n)
       i=winio@('%2nl%cn%^tt[Show]',cb_func)
      END
c-------------------------------------------
      INTEGER function cb_func()
       INTEGER n,i,j,winio@
       COMMON n
       CHARACTER*10 fmt
       fmt='Invalid value %wd'
       IF(n.eq.1) THEN
         fmt='Format %wd'
       ELSE if(n.eq.2) THEN
         fmt='FORMAT %wd'
       ENDIF
       i=winio@(fmt,n)
       cb_func=1
      END

In this example, the choice of format string for the output depends on the value entered into the edit box. The illustration is not very useful in itself but it does point the way to the idea that it is possible to construct format strings dynamically under program control.

The third and final approach to the dynamic use of winio@ takes the last idea one stage further. As it is we cannot easily change the format codes within a format string because different format codes take different arguments in the winio@ call. For example, if %wd were changed to %wf in the above example, then the call to winio@ would require a real valued argument rather than an integer after the format string. Although you could solve this problem by using complex IF or CASE constructs, ClearWin+ provides an alternative and potentially more powerful approach via the following routines:

SUBROUTINE ADD_WINIO_INTEGER@(I)
INTEGER I

SUBROUTINE ADD_WINIO_FLOAT@(X)
DOUBLE PRECISION X

SUBROUTINE ADD_WINIO_CHARACTER@(S)
CHARACTER*(*) S

SUBROUTINE ADD_WINIO_FUNCTION@(F)
EXTERNAL F

Using these routines, you create the argument list before calling winio@. After creating the list, you then call winio@ with the format string as its only argument. Here is a simple example.

      WINAPP
       INTEGER, n,i,winio@
       COMMON n
       EXTERNAL cb_func
       n=1
       i=winio@('Format 1 or 2: %4rd&',n)
       i=winio@('%2nl%cn%^tt[Show]',cb_func)
      END
c-------------------------------------------
      INTEGER function cb_func()
       INCLUDE <windows.ins>
       INTEGER n,i
       COMMON n
       CHARACTER*20 fmt
       DOUBLE PRECISION x
       x=n
       IF(n.eq.1) THEN
         fmt='Integer %wd'
         CALL add_winio_integer@(n)
       ELSE
         fmt='Real %wf'
         CALL add_winio_float@(x)
       ENDIF
       i=winio@(fmt)
       cb_func=1
      END

This example is too simple to do justice to the concept but it is sufficient to point the way.

 

 

Copyright © 1999-2017 Silverfrost Limited