Is Variable Null Method
The Is Variable Null method determines if a variant variable contains a Null value. It returns one of the following values:
-1 (negative one). The expression contains a Null value.
0 (zero). The expression does not contain a Null value.
A null variant does not contain data. It only identifies a result that is not valid or that is ambiguous. Null is not the same as Empty, which indicates that a variant is not yet set.
Format
IsNull(expression)
The following table describes the arguments that you can use with this method.
Argument | Description |
---|---|
expression |
Any expression that contains a variable of data type variant. |
Example
The following example asks for ten test score values and calculates the average. If any score is negative, then it sets the value to Null. This example uses the Is Variable Null method to reduce the total count of 10 scores to only the scores that contain a positive value before it calculates the average:
Sub Button_Click
Dim arrayvar(10)
Dim count as Integer
Dim total as Integer
Dim x as Integer
Dim tscore as Single
count = 10
total = 0
For x = 1 to count
tscore = 88
If tscore<0 then
arrayvar(x) = Null
Else
arrayvar(x) = tscore
total = total + arrayvar(x)
End If
Next x
Do While x <> 0
x = x - 1
If IsNull(arrayvar(x)) = -1 then
count = count-1
End If
Loop
msgtext = "The average (excluding negative values) is: "
msgtext = msgtext & Chr(10) & Format(total/count, "##.##")
End Sub