How do I check for an object being Nothing in VB6?

只谈情不闲聊 提交于 2019-12-30 07:56:14

问题


In my VB6 application I have an array of objects declared thus...

Dim MyArray() as MyClass

This array is filled in as processing goes on

Set MyArray(element) = passed_object

and as elements are no longer wanted,

Set MyArray(otherelement) = Nothing

When using the array, I want to use a loop like

For i = 1 To Ubound(MyArray)
    If MyArray(i) <> Nothing Then    ' Doesn't compile
        ...do something...
    End If
Next i

But I can't get anything likely-looking to compile. I've also tried

If MyArray(i) Is Not Nothing Then

Should I want to do this, and if so, what test should I put in here?


回答1:


If Not MyArray(i) Is Nothing Then



回答2:


If Not MyArray(i) Is Nothing Then



回答3:


Instead of

IsNothing(<object here>)

this should work in VB6:

<object here> Is Nothing



回答4:


    Private Function IsNothing(objParm As Object) As Boolean
        IsNothing = IIf(objParm Is Nothing, True, False)
    End Function



回答5:


In addition to the other answers (is Nothing using the is as an operator) there is also the function:

IsNothing(<object here>)

e.g.

if IsNothing(MyArray(i)) = false then

EDIT: MSDN unhelpfully states this exists in VBA and VB6, but it apparently doesn't exist in VB6 as per comments below



来源:https://stackoverflow.com/questions/5340881/how-do-i-check-for-an-object-being-nothing-in-vb6

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!