ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
SHARED Statement Example
                        Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
' This example uses the SHARED statement to share a variable between the main
' program and a SUB procedure. Each time the SUB is called, an asterisk (*)
' is added to a STATIC array.
 
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
 
 DECLARE SUB foo ()
 CLS                               ' Clear the screen
 FOR i = 1 TO 9
     CALL foo
 NEXT
 END
 
 SUB foo ()
    STATIC array() AS STRING            ' "array" is static
    STATIC flag                         ' "flag" is static
    SHARED i                            ' "i" is shared with main module only
 
    IF flag = 0 THEN                    ' Dimension array if not already
        DIM array(1 TO 9) AS STRING     ' dimensioned
        flag = 1
    END IF
 
    array(i) = STRING$(i, "*")          ' Put data into array
 
    IF i = 9 THEN                       ' Print contents of array when
        FOR j = 1 TO 9                  ' it is filled
            PRINT j; ":"; array(j)
        NEXT
    END IF
 
 END SUB