SecondBASIC Documentation v3

Home / Command Reference / Global

Global

Description: Defines a variable and sets the scope to global. This means the variable will be accessible in sub routines and functions./

Syntax:

Global <Variable> As <DataType> [* <Size>][At <Location>]

Part Description
<Variable> Required. This is the name of the variable you are declaring.
<DataType> Required. The <DataType> can be an Integer (x, y, z), Long (x&, y&, z&), or String (x$, y$, z$).
<Size> Optional. This is only used for the <DataType> String. This changes the length of the string variable from its default size (128 characters) to whatever <Size> is set to..
<Location> Optional. Sets the default value of the variable. <Location> is where the Data statements are located.

Example:

    Dim name$ As String
    Global g_name$ As String
    Global s_name$ As String
    name$ = "Second"
    g_name$ = "Dimension"
 
    PrintName
 
    Print "Welcome to "; name$; " "; s_name$
 
    End
Declare Sub PrintName()
    Print "name$: "; name$
    Print "g_name$: "; g_name$
    s_name$ = "DIMENSSSIIOOONNNN"
End Sub