So, I've been cruising these and many other forums and have found many who need help concerning this issue, but usually it's resolved using the New statement.
What I'm doing here is I first add a 2D array of PictureBoxes during runtime with the following code
For i = 0 To xVal
For z = 0 To yVal
pictures(i, z) = New PictureBox
currentPoint = New Point(startX + (z * 30), startY + (i * 30))
pictures(i, z).Location = currentPoint
pictures(i, z).Size = picSize
pictures(i, z).BackColor = Color.Black
pictures(i, z).BorderStyle = BorderStyle.FixedSingle
pictures(i, z).Name = counter
counter += 1
Next
Next
For i = 0 To xVal
For z = 0 To yVal
Me.Controls.Add(pictures(i, z))
AddHandler pictures(i, z).Click, AddressOf pictureClick
Next
Next
Then later, I have a separate Sub which is supposed to change every picturebox in the array to the same image with this code:
Private Sub All()
For i = 0 To x
For j = 0 To y
pictures(i, j).Image = New Bitmap("images/" & filePic & ".jpg")
Next
Next
End Sub
I know that the first code works because if I coment out Private Sub All() then it works fine, but the line
pictures(i, j).Image = New Bitmap("images/" & filePic & ".jpg")
returns the Object reference not set to an instance of an object error. An alternative code I had was:
Private Sub All()
Dim index As Integer
For i = 0 To x
For j = 0 To y
grid(index) = filePic
pictures(i, j).Image = New Bitmap("images/" & filePic & ".jpg")
index += 1
Next
Next
End Sub
where "grid()" was a string array holding lines of integers for map placement
Any help on this topic would be greatly appreciated... it's been stumping me for a day or so now
Edit: I had this problem in a separate location in my code and while playing around with different solutions I somehow solved it for that instance of the error, but not this one. No idea how :'(