在 VarType
MSDN VBScript 的 Microsoft 文档 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
并且,当在它们的数组中单独引用时,也返回 vbInteger
,但数组坚持它是 vbVariant
的数组.除非我在这里完全遗漏了一些东西,否则似乎在文档中没有办法创建一个数组,其中项目都是相同的类型并且具有
VarType
将其识别为数组 vbVariant
以外的任何东西.我觉得这应该已经是一个问题,但我在这里进行了空搜索,所以如果我错过了现有的问题,请随时链接。
最佳答案
In VBScript, variables are always of one fundamental data type, Variant.
变量中包含的数据可以是任何类型,但变量本身总是
Variant
类型。与 VarType
核对数组位置的内容将返回包含的数据类型。但数组本身是 Variant
的“单元格”的复合体。类型所以,在你的情况下
VarType
将返回 vbArray
(8192) + vbVariant
(12) = 8204
关于arrays - 为什么 VarType() 总是为数组返回 8204,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30511987/