在经典ASP,如何获得,如果一个动态数组有中的元素? [英] in Classic ASP, How to get if a dynamic array has elements inside?

查看:119
本文介绍了在经典ASP,如何获得,如果一个动态数组有中的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我宣布一个动态大小的数组像这样

If I declare a dynamic sized array like this

Dim myArray()

那么如何我可以在code得到,如果这数组为空或者它包含的元素?

Then how I can get in the code if this array is empty or it contains elements?

我用 IsArray的(myarray的)函数试过,给我总是正确的,

I tried with IsArray(myArray) function that give me always True,

否则,如果我尝试用 UBound函数(myarray的)函数中,我得到一个错误。

otherwise if I try with UBound(myArray) function, I get an error.

任何想法?在此先感谢,

Any ideas? thanks in advance,

最大

推荐答案

首先,一些注意事项。


  1. 使用暗淡A()不在在VBScript那么实用,更好用使用ReDim
    A(N)

  2. 例如使用ReDim A(-1)也为空数组(不包含元素),但初始化

  1. Using Dim A() is not so practical in VBScript, better use ReDim A(n).
  2. For example ReDim A(-1) is also empty array (no elements) but initialized.

和的最佳途径codeRS谈就是例子...

And as the best way coders to talk is by examples...

Dim a(), b(0), c
c = Array(a, b)
ReDim d(-1)

WScript.Echo "Testing HasBound:"
WScript.Echo "a = " & HasBound(a) & ",", _
             "b = " & HasBound(b) & ",", _
             "c = " & HasBound(c) & ",", _
             "d = " & HasBound(d)
WScript.Echo "Testing HasItems:"
WScript.Echo "a = " & HasItems(a) & ",", _
             "b = " & HasItems(b) & ",", _
             "c = " & HasItems(c) & ",", _
             "d = " & HasItems(d)

'> Testing HasBound:
'> a = False, b = True, c = True, d = True
'> Testing HasItems:
'> a = False, b = True, c = True, d = False

Function HasBound(anyArray)
    On Error Resume Next
    HasBound = UBound(anyArray)
    HasBound = (0 = Err)
    On Error Goto 0
End Function

Function HasItems(anyArray)
    For Each HasItems In anyArray
        HasItems = 1
        Exit For
    Next
    HasItems = (HasItems > 0)
End Function

正如你所见,2个功能不同的目的。所不同的是在阵列 D 其中有边界,而是有-没有项。

As you see, 2 functions with different purpose. The difference is visible on array d which "has-boundary" but "has-not-items".

这篇关于在经典ASP,如何获得,如果一个动态数组有中的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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