Results 1 to 9 of 9

Thread: Label Arrays

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    5

    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.

  2. #2

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    5

    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

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    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.

  5. #5

  6. #6
    Fanatic Member Andy_P's Avatar
    Join Date
    May 2005
    Location
    Dunstable, England
    Posts
    669

    Re: Label Arrays

    If you pass in a value of '10' (for example) through the Order parameter in your Set_Number sub:
    VB Code:
    1. Public Sub Set_Number(ByVal Order As Integer)
    2. ReDim Labelx(Order)
    3. End Sub

    This will create an array of 11 labels, (0 through 10).

    Could this be a source of trouble maybe? Just a thought.
    Using Windows XP Home sp3
    Mucking around with C# 2008 Express
    while ( this.deadHorse ) { flog( ); }


  7. #7
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: Label Arrays

    VB Code:
    1. Option Explicit On
    2.  
    3. Public Class Count
    4.     Dim Labelx() As Label
    5.     Dim IsBeat() As Boolean
    6.  
    7.     Public Sub Set_Number(ByVal Order As Integer)
    8.         ReDim Labelx(Order)
    9.     End Sub
    10.  
    11.     Public Function Get_Number(ByVal Ascend As Integer) As Label
    12. [B]        If Labelx(Ascend)=Nothing Then Labelx(Ascend)=New Label[/B]
    13.         Labelx(Ascend).Size = New System.Drawing.Size(50, 50)
    14.         Labelx(Ascend).Location = New System.Drawing.Point(Ascend * 20, 20)
    15.         Labelx(Ascend).Text = CStr(Ascend)
    16.         Labelx(Ascend).Visible = True
    17.         Return (Labelx(Ascend))
    18.     End Function
    19.  
    20. End Class
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  8. #8

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    5

    Re: Label Arrays

    Thank you, ComputerJy.

  9. #9

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    5

    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
  •  



Click Here to Expand Forum to Full Width