Error : Object referrence not set to an instance of an object
Situation;
I have an array declared publicly (i.e. outside any events) as

Public Shared array_shuffle() As Integer

What I want to do is to be able to specify the length and elements of this array from inside events such as click event, however I am getting the error (specified above). The code that is triggering the error is this line;

   array_shuffle(0) = 0

I think that the '0' inside the parenthesis is the culprit here but I am not quite sure.

Please let me know if you have other questions
Thanks

Dean

If you need to define the size of an array you can use :

ReDim Preserve array_shuffle(20);

You can use that is the methods that specify the array a size.
Preserve isn't necessary but it allows you to keep elements already specified if you've loaded some or all of the array. Data loss occurs if you redim to something smaller of course.

If the array is placed in the same codefile as the events, then public/shared modifiers are not needed.

May I suggest a list?

Dim array_shuffle As New List(Of Integer)

Lists are a class that implements the IEnumerable interface.
Therefore, you will have the ability to sort,search,add,remove and event use LINQ statements on the list.

   array_shuffle.Sort(MyIntComparer)
   array_shuffle.Add(101) 'Will add an item to the list with the value of 101
   array_shuffle.Remove(101) 'Will remove the entry of value 101

   Dim query = From iVal In array_shuffle
               Where iVal > 100
               Select iVal

   query.ToArray() 'Will return an integer array containg all values that are larger than 100.

As for comparison help please see this.

Well, thanks to both of you guys. I think I got more than enough. Very helpful.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.