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?
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 .
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).
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.
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.
If Not MyArray(i) Is Nothing Then
If Not MyArray(i) Is Nothing Then
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With