Hi, I'm trying to create a Class "Count" which will produce as many labels as stated in an argument to a given function.

Here I have Set_Number and Get_Number, with Set declaring the amounts of labels to be stated, and Get displaying the labels.

For Get, I have a for loop in the main form that will provide values for Ascend, but later I get the error message:


An unhandled exception of type 'System.NullReferenceException' occurred in WindowsApplication6.exe

Additional information: Object reference not set to an instance of an object.



It gets stuck on a line that reads:
Labelx(Ascend).Size = New System.Drawing.Size(50, 50)



Well, here is my code for Class Count. I hope you don't spend too much time trying to figure it out.

Option Explicit On

Public Class Count
Dim Labelx() As Label
Dim IsBeat() As Boolean

Public Sub Set_Number(ByVal Order As Integer)
ReDim Labelx(Order)
End Sub

Public Function Get_Number(ByVal Ascend As Integer) As Label
Labelx(Ascend).Size = New System.Drawing.Size(50, 50)
Labelx(Ascend).Location = New System.Drawing.Point(Ascend * 20, 20)
Labelx(Ascend).Text = CStr(Ascend)
Labelx(Ascend).Visible = True
Return (Labelx(Ascend))
End Function

End Class




And I know that this not a practical use of printing text, but I have a reason behind it that I am going all this way.

Best of wishes,
Ben.