Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vb6

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?

like image 331
Brian Hooper Avatar asked Mar 17 '11 15:03

Brian Hooper


People also ask

Is nothing or null in VB?

When checking whether a reference (or nullable value type) variable is null , do not use = Nothing or <> Nothing . Always use Is Nothing or IsNot Nothing . For strings in Visual Basic, the empty string equals Nothing .

Is null the same as nothing?

In mathematics, the word null (from German: null meaning "zero", which is from Latin: nullus meaning "none") is often associated with the concept of zero or the concept of nothing. It is used in varying context from "having zero members in a set" (e.g., null set) to "having a value of zero" (e.g., null vector).

Is null in vb6?

In Visual Basic 6.0, the Null keyword indicated that a field contained no valid data, and the IsNull function was used to test for Null. In addition, Visual Basic 6 supported Null propagation when Null was used in an expression, the result of the expression would also be Null.

Is not nothing in VB net?

VB.Net IsNothing Function returns a Boolean value indicating whether an expression has no object assigned to it. There is no direct, 100% equivalent of the Vb.Net function IsNothing, but the test against null accomplishes the same thing.


2 Answers

If Not MyArray(i) Is Nothing Then
like image 115
mwolfe02 Avatar answered Oct 02 '22 14:10

mwolfe02


If Not MyArray(i) Is Nothing Then
like image 33
AakashM Avatar answered Oct 02 '22 14:10

AakashM