在vb 6.0中,我们如何知道动态数组是否已初始化?

时间:2012-05-07 16:06:41

标签: arrays vb6

  

可能重复:
  How do I determine if an array is initialized in VB6?
  How do I check for an object being Nothing in VB6?

在函数返回动态数组的情况下,动态数组可能未初始化(例如,执行中的错误)。有可能检查这种情况吗?

函数IsNothing()不起作用,在这种情况下UBound()正在创建错误。

例如:

Function find(results() As String)

    [Definition here...]

End Function

[...]

Dim results() As String
find(results)
If UBound(results) > 0 Then '<-- This line will fail when results was not defined

[...]

提前致谢!

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题,无法找到一个干净的方法来做到这一点。我最终创建了自己的函数,实现了一个包含错误处理程序的Ubound。如果失败,我会返回-1。

Private Function custom_UBound(ByRef ToTest() As String)
    On Error GoTo errHandler

    custUBound = UBound(ToTest)

    Exit Function
errHandler:
    custUBound = -1
End Function
相关问题