設計思想: 在vb中數姐最大維數是60,所以我們通過錯誤捕捉來處理這個問題,在這里我們用到ubound函數 public function arrayrange(marray as variant) as integer dim i as integer dim ret as integer dim errf as boolean
errf = false on error goto errhandle '判斷代入的參數是否為數組 if not isarray(marray) then arrayrange = -1 exit function end if 'vb中數組最大為60 for i = 1 to 60 '用ubound函數判斷某一維的上界,如果大數組的實際維數時產生超出范圍錯誤, ' 此時我們通過resume next 來捕捉錯這個錯誤 ret = ubound(marray, i) if errf then exit for next i '最后返回 arrayrange = ret
exit function errhandle: ret = i - 1 errf = true resume next