|
-
Jul 14th, 2006, 05:23 PM
#1
Thread Starter
New Member
Label Arrays
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.
-
Jul 14th, 2006, 05:27 PM
#2
Re: Label Arrays
Wrong forum. You want our .Net forum.
And what was wrong with your previous thread?
-
Jul 14th, 2006, 05:31 PM
#3
Thread Starter
New Member
Re: Label Arrays
I thought this post was quite different from my previous post. Well, for me it was.
Is there a huge difference as to where I put this post? Just a thought. If there is, please explain. But yeah, I'll revive my other post in the .NET area
-
Jul 14th, 2006, 05:34 PM
#4
Re: Label Arrays
well the fact that .Net and classic VB are completely different programming languages kinda means you should post .Net questions in the .Net forum.
-
Jul 14th, 2006, 06:07 PM
#5
-
Jul 15th, 2006, 04:36 AM
#6
Re: Label Arrays
If you pass in a value of '10' (for example) through the Order parameter in your Set_Number sub:
VB Code:
Public Sub Set_Number(ByVal Order As Integer)
ReDim Labelx(Order)
End Sub
This will create an array of 11 labels, (0 through 10).
Could this be a source of trouble maybe? Just a thought.
-
Jul 15th, 2006, 04:40 AM
#7
Re: Label Arrays
VB Code:
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
[B] If Labelx(Ascend)=Nothing Then Labelx(Ascend)=New Label[/B]
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
"I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
My Blog
-
Jul 15th, 2006, 01:48 PM
#8
Thread Starter
New Member
-
Jul 15th, 2006, 02:21 PM
#9
Thread Starter
New Member
Re: Label Arrays
Hi, I've encountered another problem.
From the main form, Ascend is given different values with a for loop, but when I run the program, the program prints '0'.
Is it possible to Return different values with one function? Please help.
Public Function Get_Number(ByVal Ascend As Integer) As Label
Labelx(Ascend).Location = New System.Drawing.Point(Ascend * 20, 20)
Labelx(Ascend).Text = CStr(Ascend)
Labelx(Ascend).Visible = True
Return (Labelx(Ascend))
End Function
Thanks a bunch,
Ben
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|