
Chapter 5. Data Types
73
5.5.2 Local Variables
A local variable can be accessed only in a file where it is defined. Write
PRIVATE
preceding a
desired variable name or
DEFREG
statement.
(Example)
PRIVATE aaa%
PRIVATE bbb$[10]
PRIVATE ccc$(5,3)[30]
PRIVATE DEFREG ddd
PRIVATE DEFREG eee%(5)
Before access to a local variable, you should define it.
If used inside more than one
SUB
or
FUNCTION
function in the same file where the local vari-
able is defined, all of those variables will also have the same value.
(Example)
PRIVATE aa%
FUNCTION addaa(x)
addaa=aa%+x
END FUNCTION
SUB printaa(x)
print aa%+x
END SUB
aa%=2
print addaa(2)
printaa(2)
In the above example, the variable aa% used in "addaa" and "printaa" will have the same
value.
■
Variables with overlapping scope
If your program has a global variable and a local variable with the same name, in those files
where the variable is declared with the
GLOBAL
statement, those variables will be treated as
the same; in a file where the variable is declared with the
PRIVATE
variable, the variable is
available only in that file.
(Example) If in each of Files 1 and 2 the variable aa% is declared by the
GLOBAL
statement
but in File 3 it is not declared by the
GLOBAL
statement:
File 1
File 2
File 3
GLOBAL aa%[50]
GLOBAL aa%[50]
PRIVATE aa%[50]
If you link Files 1, 2, and 3 above into a program file, the variables aa% in Files 1 and 2 will
have the same value and aa% in File 3 will be treated as a variable different from those in Files
1 and 2.
Содержание BHT-BASIC 100 SERIES
Страница 1: ......
Страница 161: ...153 Chapter 10 Sleep Function CONTENTS 10 1 Sleep Function 154...
Страница 163: ...155 Chapter 11 Resume Function CONTENTS 11 1 Resume Function 156...
Страница 173: ...165 Chapter 13 Backlight Function CONTENTS 13 1 Backlight Function 166...
Страница 192: ...Chapter 14 Statement Reference 184 Example OPEN master Dat AS 1 FIELD 1 20 AS bar 10 AS ky CLFILE 1 CLOSE 1...
Страница 249: ...241 Example CLOSE IF kyIn Y THEN KILL Master Dat END IF Reference Statements CLFILE...
Страница 349: ...341 Run time errors Error code Meaning 05h Parameter out of the range checktype is out of the range...
Страница 383: ...375 Run time errors Reference Error code Meaning 05h Parameter out of the range Functions LEFT LEN and RIGHT...