Results 1 to 2 of 2

Thread: duplicate labels

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2003
    Location
    Newark-on-trent, Nottingham
    Posts
    243

    duplicate labels

    I am new to .net on VB six if you copied and pasted for example label1 it would create label1(0) and label1(1). Not so in VB.net which is causing me a big headache.

    I am creating a random number from 1-90 and if number 10 for example was the random number i am changing the contents of label10.text to "x".

    I do this so that i can when generating the next random number say whever or not that number has already been drawn.

    In VB6 i was able to say if Label1(RandomNumber).text="x" however in .net i have had to have a label1,abel2,label3 etc. and so the above code will not work. I hope this makes sense it should be fairly simple!!!!

  2. #2
    Frenzied Member Asgorath's Avatar
    Join Date
    Sep 2004
    Location
    Saturn
    Posts
    2,036

    Re: duplicate labels

    Hi
    Every form has a collection of controls...
    Code:
            Dim c As Control
            For Each c In Me.Controls
                If c.GetType.ToString = "System.Windows.Forms.Label" Then
                    Select Case c.Name
                        Case "Label1"
                            c.Text = "hello"
                    End Select
    
                    '' do something
                End If
            Next
    Regards
    Jorge
    "The dark side clouds everything. Impossible to see the future is."

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