使用了动态数组dim arr() as stringif x = 10 then
   redim preserve arr(10) as string
end ifx = ubound(arr)
因为X=10可能没有执行。所以 ubound(arr)可能出错。---------------------------------------------------想要

解决方案 »

  1.   

    使用了动态数组
    dim arr() as stringif x = 10 then
      redim preserve arr(10) as string
    end ifx = ubound(arr)
    因为X=10可能没有执行。所以 ubound(arr)可能出错。---------------------------------------------------又不想在大函数中使用On error处理机制。想将ubound转移到小函数中处理,
    public function  xx( arr() as ??? ) as Integer
       on error resume next
       xx = ubound(arr)
       if err.number <> 0 then
          xx = -1
       end if
    end function
    因主函数中的动态数组是自定义类型。在小函数xx中,的数组定义为Variant,会爆,缺少数组或用户自定义类型
    不晓得该怎么修改,
      

  2.   

    使用SafeArrayGetDim判断数组是否已初始化。
    Private Declare Function SafeArrayGetDim Lib "oleaut32.dll" (ByRef psa() As any) As Long
      

  3.   

    dim arr() as string
    for i=0 to 10
      redim preserve arr(i)
      arr(i)=i
    next
    x = ubound(arr)