有一个动态数组,要改变大小,但如果数组没有元素,用Ubound将出错。请问如何知道数组有没有元素?

解决方案 »

  1.   

    For each in 数组
    if not 元素 is null then msgbox "有元素" 
    next
      

  2.   

    if  isnull(xxxx(x))=ture then zzzzz
      

  3.   

    用Ubound函数,如果返回值大于0则有元素
    dim i as integer
    i = ubound(arr)
    if i>0 then
       msgbox "数组有元素!"
    end if
      

  4.   

    1楼和2楼的方法无效。我一般每一次dim ary() as long 后,都要redim ary(0)
    避免产生错误。
      

  5.   

    试试 xhema1980(无名) 的方法呢?
      

  6.   

    同意楼上,动态数组创建后,先定义维数。没有必要为了Ubound出错难为自己,就用楼上的方法
      

  7.   

    //1楼和2楼的方法无效。//我一般每一次dim ary() as long 后,都要redim ary(0)
    //避免产生错误。我指这个,呵呵
      

  8.   

    实在不行就用错误捕捉程序  当UBOUND出现-1时就说明没有元素
      

  9.   

    看来没什么更好的办法了,只能Redim了
      

  10.   

    dim a(0) as integer
    dim i as integer
    for i=1 to 100
         load a(i)
    next
    '如果没有必要,我建议这样动态加载,随时都可以加载。