Break On
Global $MYNAME ; global var to illustrate scope
Dim $ ; temp variable
Dim $TestVar, $NewTestVar ; test variables
$ = SetOption('Explicit', 'On')
; define the global with some data
$MYNAME = 'My name is ' + @WKSTA
'Set MYNAME to "' $MYNAME '"' ?
; set the variable to a known value & display it
$TestVar = @DATE
'Set TestVar to ' $TestVar ?
; Call a subroutine that will display and modify the original $TestVar value
'Calling SUB1' ?
Gosub 'Sub1'
? 'back in Main - TestVar now contains contains: ' $TestVar ?
; Call a function, pass it a copy of $TestVar for it to display and modify
; store the modified value in a new variable name
$NewTestVar = Func1($TestVar)
? 'back in Main - After calling Func1, TestVar contains "' $TestVar '"' ?
'and NewTestVar contains "' $NewTestVar '".' ?
; End of script - subroutines follow
Exit 0
:Sub1
? 'Running Sub1' ?
; proof of global visibility
'MYNAME contains "' $MYNAME '"' ?
; proof of local visibility
'TestVar contains: ' $TestVar
'... Resetting it to ' @TIME ?
$TestVar = @TIME
Return
Function Func1($_MyTestVar)
? 'Running Func1' ?
; proof of global visibility
If IsDeclared($MYNAME )
'MYNAME is visible and contains "' $MYNAME '".' ?
Else
'MYNAME is not visible!' ?
EndIF
; proof of no external local visibility
If IsDeclared($TestVar)
'TestVar is visible and contains "' $TestVar '".' ?
Else
'TestVar is not visible (as expected)!' ?
EndIF
; proof of local visibility of passed value
'The MyTestVar contains "' $_MyTestVar '". It should have data!' ?
; Changing local copy
$_MyTestVar = @TICKS
'MyTestVar now contains "' $_MyTestVar '". It should be different!' ?
; Return the modified data
$Func1 = $_MyTestVar
; return success
Exit 0
EndFunction