我怎么能确定一个动态数组没有在VBScript中的尺寸 [英] How can I determine if a dynamic array has not be dimensioned in VBScript

查看:89
本文介绍了我怎么能确定一个动态数组没有在VBScript中的尺寸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我创​​建在VBScript中动态数组

 暗淡myArray的()

后来我如何检查,看看这个数组从来没有被标注?

  UBOUND(myarray的)子脚本超出范围
LBOUND(myarray的)子脚本超出范围
为IsEmpty(myarray的)'返回false


解决方案

我不认为有内置的东西,但你可以创建自己的功能:

 功能将IsInitialized(一)
    Err.Clear
    在错误恢复下一页
    UBound函数(一)
    如果(Err.Number的= 0)然后
        将IsInitialized = TRUE
    万一
结束功能

您可以调用为:

 暗淡myArray的()
如果不将IsInitialized(myarray的)然后
    WScript.Echo未初始化
万一

然而,一种方式来解决它可能是没有声明空数组,而不是只声明一个变量并将其设置为一个数组后,所以更改上面的code为:

  myarray的暗淡
myArray的=阵列()
如果不将IsInitialized(myarray的)然后
    WScript.Echo未初始化
万一

Say I create a dynamic array in VBScript

Dim myArray()

Later on how can I check to see that this array has never been dimensioned?

Ubound(myArray) 'sub script out of range
Lbound(myArray) 'sub script out of range
IsEmpty(myArray) 'returns false

解决方案

I don't think there's anything built in, but you can create your own function as:

Function IsInitialized(a)    
    Err.Clear
    On Error Resume Next
    UBound(a)
    If (Err.Number = 0) Then 
        IsInitialized = True
    End If
End Function

Which you can then call as:

Dim myArray()
If Not IsInitialized(myarray) Then
    WScript.Echo "Uninitialized"
End If

However, one way to work around it might be to not declare empty arrays, instead declare just a variable and set it to an array later, so change the code above to:

Dim myArray
myArray = Array()
If Not IsInitialized(myarray) Then
    WScript.Echo "Uninitialized"
End If

这篇关于我怎么能确定一个动态数组没有在VBScript中的尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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