在经典 ASP 中,如何获取动态数组内部是否有元素?
如果我声明一个像这样的动态大小的数组
Dim myArray()
,那么如果该数组为空或包含元素,我如何进入代码?
我尝试使用 IsArray(myArray)
函数,该函数始终为 True,
否则如果我尝试使用 UBound(myArray)
函数,则会收到错误。
有什么想法吗?预先感谢,
马克斯
If I declare a dynamic sized array like this
Dim myArray()
Then how I can get in the code if this array is empty or it contains elements?
I tried with IsArray(myArray)
function that give me always True,
otherwise if I try with UBound(myArray)
function, I get an error.
Any ideas? thanks in advance,
Max
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
声明数组后,您必须初始化它:
然后这样的代码将始终有效:
编辑:由于您无法初始化数组,这里有更长的方法来检查它是否为空:
After declaring the array, you have to initialize it:
Then such code will always work:
Edit: as you can't initialize the array, here is longer way to check if it's empty or not:
首先是一些注释。
Dim A()
不太实用,最好使用ReDim
A(n)。
ReDim A(-1)
也是空数组(无元素),但已初始化。程序员最好的交流方式是通过示例......
如您所见,两个函数具有不同的目的。差异在数组
d
上可见,它“有边界”但“有非项目”。First some notes.
Dim A()
is not so practical in VBScript, better useReDim
.A(n)
ReDim A(-1)
is also empty array (no elements) but initialized.And as the best way coders to talk is by examples...
As you see, 2 functions with different purpose. The difference is visible on array
d
which "has-boundary" but "has-not-items".我找到了一个解决方案,我编写了一个特定的函数来检查数组是否为空;该函数不会检查它内部是否有元素,但仅检查该数组是否被声明为动态的,没有维度且没有元素。
I found a solution, I wrote a specific function to check if an array is null or not; the function doesn't check if it has elements inside but only if the array is declared as dynamic without dimensions and no elements.
我现在能想到的一件事是:
编辑:麦克斯的评论
The one thing I can think of right now is:
EDIT: Max's comment
我总是检查 UBound = 0 并且第一个元素也为空:
I've always checked for UBound = 0 and the first element is empty too: