I’m converting an application from VB6 to VB.NET, and am required to declare and initialise some controls in code (control arrays). I have it declared globally, so other forms can access the data stored within them, and then I try to manipulate them inside the Form_Load() sub:
Public lblDataZone() As Label
Private Sub Form_Load() Handles Me.Load
lblDataZone(0) = New Label
With lblDataZone(0)
.Height = 13
.Text = "Zone (l/min)"
.Left = 6
.Top = 42
End With
The error I get says “Object reference not set to an instance of an object”. I feel like I’m missing something huge here, but what’s wrong with it?
Thanks
First of all you have to instantiate the array of
Label. You can useReDim()orNewkeyword: