Microsoft KB Archive/131336

{|
 * width="100%"|

VARTYPE Function Returns Value 8204 for Variant/Array

 * }

Q131336

-

The information in this article applies to:


 * Microsoft Visual Basic for Applications version 1.0
 * Microsoft Excel for Windows, versions 5.0, 5.0c
 * Microsoft Excel for the Macintosh, versions 5.0, 5.0a
 * Microsoft Project for Windows, version 4.0
 * Microsoft Project for the Macintosh, version 4.0

-

SUMMARY
In Microsoft Visual Basic Programming System, Applications Edition, when you use the VarType function to return the value indicating the subtype of a variable, the function returns the value 8204 if your variable is defined as either of the following:


 * A variant that contains an array.
 * An array that contains variant data type.

Note that the VarType function never returns the value 8192 for the vbarray subtype. This is by design, because if your variable is an array, the VarType function returns a value indicating not only that the variable is an array, but also the type of the elements that the array contains.

MORE INFORMATION
When you use the VarType function to return the subtype of your variable, the function returns the value 8204 for a variable that is an array of type Variant (8192 for Array + 12 for Variant). If your variable is a Variant that contains an array, the function also returns the value 8204. An array of type Variant is exactly the same as a Variant that contains an array. The following Visual Basic example demonstrates this:

Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose.

Visual Basic Example
The following procedure shows that the variable q, defined as a variant containing an array of values, x, y, and z, is actually an array of variant data types.

Sub VarConArray ' Dimension variables Dim x As Integer, y As Integer, z As Integer Dim q As Variant

' Set value of variable q equal to variant containing ' array of integer data type q = Array(x, y, z)

MsgBox VarType(q)       ' returns value 8204 MsgBox TypeName(q)      ' returns value Variant MsgBox TypeName(q(1))   ' returns value Integer

' assign first element in array to string value "test" q(1) = "test"

MsgBox VarType(q)       ' returns value 8204 MsgBox TypeName(q)      ' returns value Variant MsgBox TypeName(q(1))   ' returns value String

End Sub Even though each element of the array q is dimensioned as an Integer data type, you can assign the value of any of the elements to a String type variable without receiving an error message. Additionally, when you use the TypeName function to return the type of one of the elements of q, the value String is returned, instead of Integer.

Therefore, when you dimension an array as Variant data type, each element of the array is Variant data type. That is, an array of variants is the same as an array dimensioned as Variant data type as in the following example:

  Dim x(3) As Variant