为什么VarType()总是为数组返回8204 [英] Why does VarType() ALWAYS return 8204 for Arrays
问题描述
在 VarType
MSDN 上面说的VBScript VarType
函数的Microsoft文档(以粗体显示):
In the VarType
MSDN Microsoft documentation for VBScript's VarType
function it says (With bold emphasis):
备注VarType函数从不通过以下方式返回Array的值 本身.总是将其添加到其他值以指示一个数组 特定类型. Variant的值仅在具有 已添加到Array的值中,以指示 VarType函数是一个数组. 例如,为 整数数组的计算结果为2 + 8192或8194 .如果一个物体有 一个默认属性,VarType(对象)返回其默认类型 财产."
"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."
但是
例如
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)))
返回
2
2
2
8204 - 8192 = 12
8204 - 8192 = 12
2
I1
-I3
全部返回其正确的vbInteger
并且,当在其数组中单独引用时,ALSO还返回vbInteger
,但该数组坚持认为它是vbVariant
的数组.
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
.
除非我在这里完全丢失了某些内容,否则似乎在文档的SPITE中没有办法创建一个数组,其中所有项均为SAME类型,并且VarType
将其识别为除数组之外的任何东西. 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.