I hope someone can point out to me what I am doing wrong here. I have a set of picture boxes in an array. If I use the following code with the PictureBox array declared in the private sub, there is no issue. If I put the array as part of a public class so that I can access the array from other private functions, I get the Nullreference error. I don't understand why!
Public class
'declare my array
Dim Pboxes() As PictureBox = {PB1, PB2, PB3, PB4, PB5, PB6, PB7, PB8}
Dim TBoxes() As TextBox = {TB1, TB2, TB3, TB4, TB5, TB6, TB7, TB8}
Private Sub Test
'call a function
Call ClearBoxes(Pboxes, TBoxes)
End sub
Public Sub ClearBoxes(ByRef Pics() As PictureBox, ByRef Txt() As TextBox)
For i As Integer = 0 To 7
If Not (Pics(i).Image Is Nothing) Then <<<<<< Nullref at this point
Pics(i).Image.Dispose()
Pics(i).Image = Nothing
End If
Txt(i).Text = Nothing
Next i
End Sub
End class