The Null keyword is used with a:
Variant | Handle = Null
Boolean = IsNull(Variant | Handle)
Variant variables are not set to Null unless you explicitly assign Null to them, so if you don't use Null in your application, you don't have to write code that tests for and handles it. You can assign Null as follows:
Dim v As Variant = Null
You can use the variant function IsNull to test if a Variant variable contains Null:
If IsNull(variant) Then Print "Variant contains Null"
Data "#Null#" can be used with Data lines to initialize a Variant.
A handle data type can simply be compared with Null. Here Null is defined as CHandle(0).
If hWnd == Null Then Print "Handle is Null"
For API functions that have parameters declared as ByRef, the Null value may be passed (if that API function can handle a Null value), in contrast to the number 0.
OpenW 1
Local a As Variant, b As Handle, x%
Print IsNull(b) // result True
a = ""
Print IsNull(a) // result 0
b = 2
Print IsNull(b) // result False
b = 0
Print IsNull(b) // result True
x% = Null
Print IsNull(x%) // result False
Print "Press any key to close"
KeyGet x%
CloseW 1
Null is commonly used in database applications to indicate unknown or missing data. Because of the way it is used in databases, Null has some unique characteristics:
- Expressions involving Null always result in Null. Thus, Null is said to "propagate" through expressions; if any part of the expression evaluates to Null, the entire expression evaluates to Null.
- Passing Null, a Variant containing Null, or an expression that evaluates to Null as an argument to most functions causes the function to return Null.
- Null values propagate through intrinsic functions that return Variant data types.
Null should not be confused with the Empty value which is used to indicate an uninitialized Variant variable or Missing which is used to indicate an optional Variant or String parameter was not passed. Furthermore, a value of 0 (zero) or a zero-length string in a Variant is not the same as Null.
Nothing, IsNothing, Empty, IsEmpty, Missing, IsMissing
{Created by Sjouke Hamstra; Last updated: 20/06/2017 by James Gaite}