arrays - 为什么 VarType() 总是为数组返回 8204

标签 arrays vbscript

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 以外的任何东西.

我觉得这应该已经是一个问题,但我在这里进行了空搜索,所以如果我错过了现有的问题,请随时链接。

最佳答案

来自 documentation

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/

相关文章:

javascript - 使用 Fetch API 时出现此错误 : Uncaught (in promise) TypeError: packages. map 不是函数

javascript - 通过 Enterprise Architect 中的脚本访问嵌套元素

mysql - 你如何解决这个错误 : MySQL ODBC Access denied for user 'ODBC' @'localhost' ?

sql-server-2008 - 为什么我会收到数据提供商或其他服务返回的 E_FAIL 状态? SQL native 客户端

process - 使用 vbscript 进行进程间通信

c - 有没有一种算法可以在线性时间内计算数组反转?

python - 提取值高于阈值的 numpy 数组的子数组

vbscript - 0x800a0e7c - ADODB.Parameters : Parameter object is improperly defined. 提供的信息不一致或不完整

javascript - 将变量传递给数组列表

jQuery inArray 给出错误的结果