Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

"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
Posted

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

[sIGPIC]e[/sIGPIC]
Posted

yes I was looking for the "is nothing" thingy.... heh, my bad... forgot parentheses after the array...

 

 

thank you...

"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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...