
Chapter 5. Data Types
75
5.5.4 Common Variables
A common variable should be declared in a main object beforehand. To share the common
variable by files other than the main object, you need to declare it with the
COMMON
statement
in each file where the common variable should be available.
File 1
File 2
DECLARE SUB printaa(x)
COMMON a%
COMMON a%
SUB printaa(x)
a%=2
print a%+x
printaa(5)
SUB
To use a% as a common variable in Files 1 and 2, define the variable with the
COMMON
state-
ment in each file.
If a common variable declared with the
COMMON
statement is used within the
SUB
or
FUNC-
TION
function in a file where the variable is defined, then the common variable will have the
same value.
(Example)
COMMON 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, variables aa% used in "addaa" and "printaa" will be treated as same
one.
Summary of Contents for BHT-BASIC 100 SERIES
Page 1: ......
Page 161: ...153 Chapter 10 Sleep Function CONTENTS 10 1 Sleep Function 154...
Page 163: ...155 Chapter 11 Resume Function CONTENTS 11 1 Resume Function 156...
Page 173: ...165 Chapter 13 Backlight Function CONTENTS 13 1 Backlight Function 166...
Page 249: ...241 Example CLOSE IF kyIn Y THEN KILL Master Dat END IF Reference Statements CLFILE...