为什么VarType()总是为数组返回8204 [英] Why does VarType() ALWAYS return 8204 for Arrays

查看:225
本文介绍了为什么VarType()总是为数组返回8204的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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.

推荐答案

来自

在VBScript中,变量始终是一种基本数据类型, 变体.

In VBScript, variables are always of one fundamental data type, Variant.

变量中包含的数据可以是任何类型,但是变量本身始终是Variant类型.用VarType检查数组位置的内容将返回包含的数据类型.但是数组本身是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

因此,在您的情况下,VarType将返回vbArray(8192)+ vbVariant(12)= 8204

So, in your case VarType will return vbArray (8192) + vbVariant (12) = 8204

这篇关于为什么VarType()总是为数组返回8204的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆