Optional Type
Normally, a variable is required to have a value.
For instance, a variable of type
Number will always contain some number, by default zero.
Sometimes it is useful to have a variable that may or may not have a value.
dim a as Number
print a
dim b as Optional Number
print HasValue(b)
b = 5
print HasValue(b)
print Value(b)
This example demonstrates the usage of an
Optional type.
Declare a variable with
dim and include the keyword
Optional before the type.
The variable will initially contain no value.
Use
HasValue to check whether an
Optional variable contains a value.
If it does, usa
Value to retrieve the value.