This executable allows you to define variables and constants.
Constants
The basic syntax for defining a constant is:
constant <name of constant> = <value expression>
Where <value expression> is either an expression that equates to a text string or an expression that equates to a numerical value.
For convenience (laziness?) multiple constants can be defined on a single command line, separated by a comma ,
So the following are valid:
Constant fred = "hello"
Constant john = 3
Constant derf = 34 * john , mike = fred , ekim = fred & " world"
So in this example derf = 102 and ekim = “hello world”
For historic reasons this executable will accept constant and const as the keyword for defining constants.
Variables
The basic syntax for defining a variable is similar to the syntax for a constant :
(Multiple definitions are allowed on a command line, separated by a comma ,
)
' uninitialized scalar untyped variable
Variable <name of constant>
e.g. variable fred
——————-
' initialized scalar untyped variable
Variable <name of constant> = <value expression>
Where <value expression> is either an expression that equates to a text string or an expression that equates to a numerical value.
e.g. variable fred = 0x01234
or variable fred = "Hello"
——————-
' uninitialized scalar variable, whose type can not be changed, only its value
Variable <name of constant> as <type keyword>
Where <type keyword> is one of the following (without any enclosing "
)
- BYTE 8 bit unsigned
- BOOLEAN true / false
- INTEGER 16 bit signed integer
- LONG 32 bit signed integer
- INT 64 bit signed integer
- SINGLE 32 bit floating point
- DOUBLE 64 bit floating point
- CURRENCY a Microsoft currency value
- DATE a Microsoft date value
- OBJECT 64 bit object identity
- STRING a bstr: a counted, zero terminated string , using 16 bit wide-characters
- VARIANT a reference to a VARIANT
These <type keyword> are provided for basic compatibility with other OLE applications.
Now, do not panic, lazy programming practice ( err, for example mine!) is to not define a variable with a type.
But good practice prefers it!
99.9% of the time you will probably only need int , double and string!
e.g. variable fred as int
or variable fred as string
e.g. variable fred = 0x01234 as int
or variable fred = "Hello" as string
Variable Arrays
This executable supports variable arrays using a fairly common syntax for programming languages based on the BASIC programming language.
' uninitialized untyped variable array
Variable <name of constant> ( <integer expression>)
Where <integer expression> is the number of elements in the array, indexed from zero ( 0
)
e.g. variable fred (5)
Individual elements in an untyped array can be set to any valid type.
e.g. the following is valid:
newscript
dim fred ( 5 )
fred(0) = 9
fred(1) = "hello"
——————-
' uninitialized typed variable array
Variable <name of constant> ( <integer expression> ) as <type keyword>
Where <integer expression> is the number of elements in the array, indexed from zero ( 0
), and the valid <type keywords> are as listed earlier above.
e.g. variable fred ( 5 ) as int
Individual elements in a typed array can only be assigned a value of the appropriate type.
e.g. the following will fail on the line fred(1) = "hello"
newscript
dim fred ( 5 ) as int
fred(0) = 9
fred(1) = "hello"
Multi-dimension Variable Arrays
This executable supports multi-dimension variable arrays using a fairly common syntax for programming languages based on the BASIC programming language.
' uninitialized untyped variable array
Variable <name of constant> ( <integer expression>,<integer expression>,.... )
' uninitialized typed variable array
Variable <name of constant> ( <integer expression>,<integer expression>,.... ) as <type keyword>
Custom Variable related commands
The following are array related commands that I think are not commonly provided, but that I consider to be occasionally useful (mainly when calling a Dynamic Link Library procedure).
——————-
Array
A function that given a list of comma separated values, creates a “VARIANT array” to hold those values.
The individual array elements are VARIANTS , so the array does not need to be “homogenous”newscript
dim fred = array ( 1, "hello" , 3 , "bye")
message = fred (0) & " " & fred (1) & " " & fred (3) & " " & fred (2)
——————-
TextToByteArray
Create a single dimension array of bytes, optionally initialised, that can be assigned to a variable.
function TextToByteArray (<character string> , optional <subsequent numeric value>, optional <subsequent numeric value>…. )
If a <subsequent numeric value> is numeric but occupies more than 1 byte , then only the low order BYTE is used
Example:dim fred = TextToByteArray ( "Hello World" )
dim mike = TextToByteArray ( "Hello World" , 0x0a , 0x0d, 0 )
Technical Note: these values occupy contiguous memory
Useful when interfacing to a DLL procedure that wants a zero terminated 8-bit character string, see the DLL demo MessageBox ANSI under the help menu.
——————-
ByteArray
Create a single dimension array of bytes, optionally initialised, that can be assigned to a variable.
function ByteArray (<number of elements> , optional <initial value>, optional <initial value>…. )
If an <inital value> is not numeric an error occurs
If the number of <inital values> is greater than the <number of elements> an error occurs
If an <initial value> is numeric but occupies more than 1 byte , then only the low order BYTE is used
Example:dim fred = ByteArray (4)
dim mike = ByteArray (5 , asc("A") , 0x042 , 63 , 64 )
fred(0) = mike (3)
message = fred (0)
Technical Note: these values occupy contiguous memory
The following is used in the function CreateEmptyZipFolder in the System macros Panel.
dim zfb(22) as byte
zfb (0) = 80
zfb (1) = 75
zfb (2) = 05
zfb (3) = 06
dim zfb = byteArray ( 22 , 80 , 75, 5, 6)
——————-
WordArray
Create a single dimension array of words, optionally initialised, that can be assigned to a variable.
function WordArray (<number of elements> , optional <initial value>, optional <initial value>…. )
If an <initial value> is not numeric an error occurs
If the number of <initial values> is greater than the <number of elements> an error occurs
If an <initial value> is numeric but occupies more than 2 bytes, then only the low order WORD is used
Example:
dim fred = WordArray (4)
dim mike = WordArray (5 , asc("A") , 0x042 , 63 , 64 )
fred(0) = mike (3)
message = fred (0)
Technical Note: these values occupy contiguous memory
——————-
DwordArray
Create a single dimension array of DWORDS (4 byte values) , optionally initialised , that can be assigned to a variable.format: DWordArray (<number of elements> , optional <initial value>, optional <initial value>.... )
If an <initial value> is not numeric an error occurs
If the number of <initial values> is greater than the <number of elements> an error occurs
If an <initial value> is numeric but occupies more than 4 bytes, then only the low order DWORD is used
Example:
dim fred = DWordArray (4)
dim mike = DWordArray (5 , asc("A") , 0x042 , 63 , 64 )
fred(0) = mike (3)
message = fred (0)
Technical Note: these values occupy contiguous memory
——————-
QwordArray
Create a single dimension array of QWORDS (8 byte values) , optionally initialised , that can be assigned to a variable.format: QWordArray (<number of elements> , optional <initial value>, optional <initial value>.... )
If an <initial value> is not numeric an error occurs
If the number of <initial values> is greater than the <number of elements> an error occurs
If an <initial value> is numeric but occupies more than 8 bytes, then only the low order QWORD is used
Example:
dim fred = QWordArray (4)
dim mike = QWordArray (5 , asc("A") , 0x042 , 63 , 64 )
fred(0) = mike (3)
message = fred (0)
Technical Note: these values occupy contiguous memory
——————-
TextToWordArray
Converts a text expression to a fixed size memory area that can be accessed as an array of WORDs (i.e. 16 bits).
The word array includes a terminating zero value.
Example:
dim fred = TextToWordArray ("ABäC")
message = fred (0) & " " & fred (1)& " " & fred (3)& " " & fred (2)