DR00ME Posted May 28, 2006 Posted May 28, 2006 Hello, how do I check if an array exists or there is reserved memory for it? I need it in situation like this... 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 Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Leaders snarfblam Posted May 28, 2006 Leaders Posted May 28, 2006 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. 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 Quote [sIGPIC]e[/sIGPIC]
DR00ME Posted May 28, 2006 Author Posted May 28, 2006 yes I was looking for the "is nothing" thingy.... heh, my bad... forgot parentheses after the array... thank you... Quote "Everything should be made as simple as possible, but not simpler." "It's not that I'm so smart , it's just that I stay with problems longer ." - Albert Einstein
Diesel Posted May 29, 2006 Posted May 29, 2006 Why not use more high level data structures in a more object oriented fashion? Translation: That's some ugly code! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.