Results 1 to 4 of 4

Thread: VB.Net help

  1. #1
    handscombmp
    Guest

    VB.Net help

    I'm currently teaching myself vb.net and i like to think that i'm getting along ok with it but i've hit a problem.
    I've simplified the problem so it just includes the bit which i know will fix it.

    I'm developing in windows form mode and i've got 10 labels.
    Now i want each of these labels to say something like

    I'm Label 1
    I'm Label 2
    I'm Label 3
    .etc

    Now the code i've been trying to use is
    For count = 1 to 10

    label(count).text = "I'm label " & count

    Next
    Now the part it's not happy with is in blue.

    Has anyone got any ideas to help me out.

    Thanks

  2. #2
    Registered+
    Join Date
    Aug 2009
    Posts
    53
    Thanks
    1
    Thanked
    3 times in 3 posts

    Re: VB.Net help

    Try this

    Code:
    Dim labelArray() As System.Windows.Forms.Label = {Me.Label1, Me.Label2, Me.Label3, Me.Label4}
    For count As Integer = 0 To 3
    	labelArray(count).Text = "I'm label " & count + 1
    Next count

  3. #3
    handscombmp
    Guest

    Re: VB.Net help

    Quote Originally Posted by jimbo90210us View Post
    Try this

    Code:
    Dim labelArray() As System.Windows.Forms.Label = {Me.Label1, Me.Label2, Me.Label3, Me.Label4}
    For count As Integer = 0 To 3
    	labelArray(count).Text = "I'm label " & count + 1
    Next count
    Can't seem to get it working.
    Throws up an error saying 'Object reference not set to an instance of an object.'

  4. #4
    Member
    Join Date
    Jan 2010
    Location
    Luton
    Posts
    195
    Thanks
    30
    Thanked
    21 times in 18 posts
    • The_Wheelhouse's system
      • Motherboard:
      • Gigabyte GA-X58A-UD3R
      • CPU:
      • Intel i7 930
      • Memory:
      • 6GB
      • Storage:
      • 1TB F3
      • Graphics card(s):
      • XFX Radeon HD 5830
      • PSU:
      • XFX 650W XXX Edition
      • Case:
      • Haf 922
      • Operating System:
      • Windows 7 Home Premium 64bit
      • Monitor(s):
      • 21.5" Dell
      • Internet:
      • Virgin

    Re: VB.Net help

    Would it not be easier to just write it out separately, e.g

    label1.text = "I'm label 1"
    label2.text = "I'm label 2"
    etc.

    The code that was provided does work, out of interest what is the event that starts the code

    For the 'Object reference not set to an instance of an object' have you declared everything.
    Last edited by The_Wheelhouse; 10-07-2010 at 02:32 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •