Variant = Empty Boolean = IsEmpty(Variant)
Generally, when a variable is created, its value is automatically initialised by GFA-BASIC32 (unlike C++) as a zero for numerical values or a zero-length string ("") for strings; however, when a Variant is created, it can not always be initialised according to its variable type as that may not be known until a value is assigned, so, instead, it is considered to be Empty.
As every Variant must technically have a value, a special Empty value is supported for Variants which have had no other value assigned. This special value has a VarType of 0 and is really just a block of 16 bytes all containing the value zero. One advantage to having this special value is that Variants which have previously been initialised with a value, and thus a variable type, can be 'uninitialised' by assigning it the Empty value. Furthermore, if an automation object held in a Variant is set to Empty, the automation object is set to Nothing.
When you use a Variant in an expression which is uninitialised and thus Empty, GFA-BASIC32 will substitute either 0 or a zero-length string, depending on the expression. Nevertheless, sometimes you may need to know if a Variant variable has been initialised since the variable was created and to do this, you can use the IsEmpty function which will return TRUE if no value has been assigned.
The Empty value disappears as soon as any value is assigned to a Variant variable (including the value of 0, the zero-length string, and the Null value).
Local vnt As Variant
Print "Is vnt Empty? ... "; IsEmpty(vnt) // Confirms that vnt is Empty
Print "2 + vnt = "; 2 + vnt // If added to a number then GFA assumes a value of 0
Print "'Hello' + vnt = "; "Hello" + vnt // If added to a string then GFA assumes a zero-length string
If IsEmpty(vnt) Then vnt = 0
Print "Is vnt Empty? ... "; IsEmpty(vnt) // Confirms that vnt is no longer Empty
vnt = Empty
Print "Is vnt Empty? ... "; IsEmpty(vnt) // Confirms that vnt is once again Empty
The Empty value should NOT be confused with either the Null value, which indicates that the Variant variable intentionally contains no valid data, or the Missing value, which is generally used to indicate that an optional Variant parameter to a function or procedure has not been passed.
{Created by Sjouke Hamstra; Last updated: 20/06/2017 by James Gaite}