1

The following procedure has worked before, but won't work at all:

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

Dim Labels() As Label = New Label() {Label1, Label2, Label3}

end sub

Private Sub Labels_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
        Handles Label1.Click, Label2.Click, label3.Click

    for i = 0 to 2
        Labels(i).BackgroundImage = My.Resources.buttonBselected 'NOT WORKING!!!
    next
end sub

It turns "NullReferenceException" message. How can I declare the labels array global or etc? (VS 2010)

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
Serhat
  • 53
  • 6
  • You need a form level array (its not global). See [Reference variables and objects elsewhere in a form](http://stackoverflow.com/q/33248704/1070452) You declared the array inside form load so that is the only place it exists and/or it isnt the same one as declared elsewhere – Ňɏssa Pøngjǣrdenlarp Jul 29 '16 at 18:41
  • @plutonix, Declaring labels after "Public Class Form1" not working again. – Serhat Jul 29 '16 at 18:46
  • Well, it wont work until you remove the local declaration in form load. You should read up on what `Dim / Private / Public` do. – Ňɏssa Pøngjǣrdenlarp Jul 29 '16 at 18:49

0 Answers0