196
LOCAL Directive
Designation of Local Data
Format
Where:
array_name[$] Numeric or string variable to be dimensioned as an array.
OBJECT
Optional keyword identifies that the property contains an object
identifier to another object.
prop1,
Property names treated like any other variable in the system. (In
prop2 ...
Object Oriented Programming, data is referred to as properties.)
varlist
Variables to be used temporarily in the execution of a subroutine,
subprogram, FOR/NEXT, SWITCH/END SWITCH, WHILE/WEND,
REPEAT/UNTIL, or user-defined function.
Description
The LOCAL directive is used to reassign variable names temporarily within a called
procedure, without affecting the original contents (if any). In Object Oriented
Programming (OOP), the LOCAL directive is similar to the PROPERTY directive, but
is used to declare data that is only visible to processing logic within the object itself.
Format 1: Assign Local Variables
LOCAL varlist
Use this format to reassign variable names temporarily, without affecting the original
contents. If the variable name supplied in the LOCAL directive is in current use, ProvideX
will preserve its value/contents. Once the current FOR/GOSUB stack has been cleared or
the program is exited, ProvideX restores variables that were designated local to their
original values. (Local variables are only active until the current stack is cleared.)
The LOCAL directive can take an assignment during declaration; however, direct
assignment does not work for arrays that are declared as local.
Example:
In the example below, X is designated as local for both subroutines (CHK_IT and
LOOP), so the value of X is restored to its original value "1234" after the GOSUB
stack is cleared for each subroutine. Since X$ was not designated as LOCAL in the
LOOP subroutine, its value has changed from "START TEST, X=" to "LOOP" after the
GOSUB stack for the LOOP has been cleared.
1030
LET X=1234,X$="START TEST, X="; PRINT X$,X
1040
GOSUB CHK_IT
1050
PRINT "TEST DONE"
1060
GOSUB LOOP
1070
PRINT X$,X," DONE"; STOP