Question Arrays using IndexOf ?

likdaboo

New member
Joined
Jun 11, 2013
Messages
2
Programming Experience
3-5
This is probably a really simple issue but i have search around and cant find an answer

I have a structure set up and am using a varaible in the structure called "type"
The array connected to the structure is called "data_Array()"
All i want to do is do a IndexOf or Substring with this but every time it crashes with "Object reference not set to an instance of an object."

VB.NET:
Dim CurrentType as String
For i = 1 to 10
CurrentType = data_array(i).type

if CurrentType.IndexOf("Main") <> -1 then 'Crashes on this line
MsgBox("It Found 'Main' ")
End If
Next

Just cant understand why this does not work, i have msgboxed the "CurrentType" varaible and that shows up correctly so the array and structure works
Any help please, i need this built before the weekend

Thanks
likdaboo
 
Hi i hope this helps you but i'm no pro :S

Are you sure their is a 10 in your array, as an array is Zero based could it possibly be
VB.NET:
For i = 0 to 9

the only thing i can think of is their must be something wrong with the array when trying to IndexOf
 
That isn't the problem. If that was the problem then you'd be getting an IndexOutOfRangeException on this line:
CurrentType = data_array(i).type
The issue is something else. I'm guessing that the 'type' field is Nothing by default and you are never actually setting it. Show us the definition of your structure and how you create and populate the array.
 
Glad you got it working, but i would still give jmcilhinney what he want's, he's very good at what he does, so their might be an under lying problem which he can help you to learn how not to encounter it again :D

but we all make the simplest mistakes
 
Back
Top