In the VarType
MSDN Microsoft documentation for VBScript's VarType
function it says (With bold emphasis):
"Remarks The VarType function never returns the value for Array by itself. It is always added to some other value to indicate an array of a particular type. The value for Variant is only returned when it has been added to the value for Array to indicate that the argument to the VarType function is an array. For example, the value returned for an array of integers is calculated as 2 + 8192, or 8194. If an object has a default property, VarType (object) returns the type of its default property."
BUT
Code such as
Dim A,I1, I2, I3
I1 = 1
I2 = 2
I3 = 3
A = Array(I1,I2,I3)
Dim A2
A2 = Split("Test,Test,Test",",")
AT = VarType(A)
AT2 = VarType(A2)
IT1 = VarType(I1)
IT2 = VarType(I2)
IT3 = VarType(I3)
WScript.Echo IT1
WScript.Echo IT2
WScript.Echo IT3
WScript.Echo AT & " - 8192 = " & AT - 8192
WScript.Echo AT2 & " - 8192 = " & AT2 - 8192
WScript.Echo CStr(VarType(A(2)))
returns
2
2
2
8204 - 8192 = 12
8204 - 8192 = 12
2
I1
- I3
ALL return their proper vbInteger
AND, when referenced individually in their array, ALSO return vbInteger
, but the array insists it's an array of vbVariant
.
Unless I'm COMPLETELY missing something here it seems that in SPITE of the documentation there is no way to create an array where the items are ALL of the SAME type and have VarType
recognize it as as anything but an array of vbVariant
.
I feel like this should already be a question but i came up empty searching through here so feel free to link if I missed the existing questions.
VarType ( varname ) The required varnameargument is a Variant containing any variable except a variable of a user defined type. Return Values. Constant. Value.
Then, open the VarType function. Now, enter the variable name as the argument of the VarType function. Now, run the code and see what we get in the message box. We got the result as 8 because VBA has certain codes for each kind of variable data type, so below is the detailed list for you.
From documentation
In VBScript, variables are always of one fundamental data type, Variant.
Data contained in the variable can be of any type, but variables itself are always of Variant
type. Checking with VarType
the contents of a position of an array will return the type of data contained. But the array itself is a compound of "cells" of Variant
type
So, in your case VarType
will return vbArray
(8192) + vbVariant
(12) = 8204
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With