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.
COMMON Statement Example
                        Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
' This example uses the COMMON SHARED statement to share access to a
' variable in a multiple-module application.
 
' To try this example:
' 1. Choose New Project from the File menu
' 2. Choose New Form from the File menu to create a form with a text box
'    and a command button
' 3. Make the text box at least 35 characters wide
' 4. Press Alt+F4 to return to the programming environment
' 5. Copy the first section of code example below to the form module
' 6. Choose New Module from the File menu to create and add the module
'    MODULE.BAS to the project
' 7. Copy the second section of code example below to the code module,
'    MODULE.BAS
' 8. Choose Code from the View menu and select FORM1.FRM to return to the
'    start-up module
' 9. Press F5 to run the example
 
' The section of code below goes in FORM1.FRM.
 
 COMMON SHARED Sampletext$
 COMMON SHARED i%
 
 SUB Command1_Click ()
     i% = i% + 1                        ' Modifies and shares i%
     CALL ChangeText
     Text1.Text = Sampletext$           ' Displays shared Sampletext$
 END SUB
 
' The section of code below goes in MODULE.BAS.
 
 DECLARE SUB ChangeText ()
 ' $FORM Form1                          ' Share form properties
 COMMON SHARED Sampletext$
 COMMON SHARED i%
 
 SUB ChangeText ()
     SELECT CASE i%
     CASE 1
          Sampletext$ = "First there was a form"
          Form1.BackColor = 13
     CASE 2
          Sampletext$ = "Then there was a control"
          Form1.BackColor = 5
     CASE ELSE
          Sampletext$ = "Now there is a project"
          Form1.BackColor = 4
     END SELECT
 END SUB