Empty

This keyword/value can only be used in conjunction with the Variant data type.
This keyword/value is used when a variable declared as Variant has not been assigned a value.
A variant variable has the Empty value prior to it being assigned a value.


Initialising a Variant

The Empty data type is the default value when you declare a variable as a Variant.

Dim myVariant As Variant 
If (myVariant = Empty) Then
End If

Empty = 0

The Empty keyword is also a zero value.
A variant containing Empty is 0 when used in a numerical context.

Dim myVariant As Variant 
If (myVariant = 0) Then
   Call MsgBox("zero value")
End If

Empty = ""

The Empty keyword is also a zero length string
A variant containing Empty is a zero length string ("") when used in a string context.

Dim myVariant As Variant 
If (myVariant = "") Then
   Call MsgBox("empty string value")
End If

Assigning Empty

The Empty data type can be assigned explicitly to a Variant data type to indicate that a variable does not contain a value.

Dim myVariant As Variant 
myVariant = "sometext"
myVariant = Empty

IsEmpty Function

The ISEMPTY returns True or False indicating if a variable has been initialised

Dim myVariant As Variant 
If (IsEmpty(myVariant) = True) Then
   Call MsgBox("empty value")
End If

vbVarType.vbEmpty

If you assign a variable to vbEmpty then you are actually just assigning the numerical value zero.

Dim myVariant As Variant 
myVariant = "some text"
myVariant = varType.vbEmpty
If (IsEmpty(myVariant) = True) Then
'This is False because the myVariant variable has been assigned the value 0.
End If


© 2018 Better Solutions Limited. All Rights Reserved. © 2018 Better Solutions Limited TopPrevNext