问题
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