Array problem

DR00ME

Centurion
Joined
Feb 6, 2004
Messages
169
Location
Finland
Hello, how do I check if an array exists or there is reserved memory for it?

I need it in situation like this...

Code:
Private SC as Byte ' Selected Curve

If ArrayC(SC).DotArray(0) "exists" Then 'Here I want to check if there is reserved memory for e.g. first place of the array, if not then i reserve it and put mouse cordinates in it..

            ReDim Preserve ArrayC(SC).DotArray(0)
            ArrayC(SC).DotArray(0).X = e.X
            ArrayC(SC).DotArray(0).Y = e.Y

End if
 
To check if an array is created, compare it to Nothing. To see how many elements are declared for an array, compare to the Array.Length property.
Visual Basic:
Imports System.Windows.Forms
 
Dim MyArray As Byte()
    
Sub CreateMyArray()
    MessageBox.Show("Creating Array.")
    MyArray = New Byte() {1, 2, 3, 4}
End Sub
 
'Checking if an array is declared.
Sub CheckMyArray()
    If MyArray Is Nothing Then
        MessageBox.Show("Array Not Created.")
    Else
        MessageBox.Show("Array Created.")
    End If
End Sub
 
'Checking that a specified index exists  
Sub CheckElements(Index As Integer)
    If MyArray Is Nothing OrElse MyArray.Length <= Index Then
        MessageBox.Show("Index " & Index.ToString() & " does not exist.")
    Else
        MessageBox.Show("Index " & Index.ToString() & " does exist.")
End Sub
    
'Demonstration
Public Sub Demo
    CheckArray()
    CreateArray()
    CheckArray()
    CheckElements(3)
    CheckElements(4)
End Sub
 
yes I was looking for the "is nothing" thingy.... heh, my bad... forgot parentheses after the array...


thank you...
 
Why not use more high level data structures in a more object oriented fashion?

Translation: That's some ugly code!
 
Back
Top