Results 1 to 2 of 2

Thread: Dynamic controls or EVAL statement

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2002
    Posts
    142

    Dynamic controls or EVAL statement

    I have an array full of values. I want to assign each value to a label.

    Is there any way you could do something like this:
    VB Code:
    1. for i=0 to ubound(array)
    2. label(i).text=array(i)
    3. next

    Desired Results:
    label1.text=43
    label2.text=64
    label3.text=87
    etc.....


    Cheers,
    Bebandit

  2. #2
    Hyperactive Member
    Join Date
    Jun 2001
    Location
    Buffalo, NY
    Posts
    297
    Bebandit,

    I've done a lot of similar things in my code, ready for the solution I found?

    When you create those labels, create them on the fly in code, and assign them to a separate collection. Then you can use the Key value of the collection. See Below:


    Code:
    Public Class MyForm
    
    Private LabelCollection as New Collection
    
    ...
    
       Private Sub MakeLabelControls
          Dim LblTemp As System.Windows.Forms.Label
    
          For intX = 0 To UBound(MyArray)
             LblTemp = New System.Windows.Forms.Label
             LblTemp.X = ...
             LblTemp.Y = ...
             LblTemp.Text = ""
             Controls.Add(LblTemp) 
             LabelCollection.Add(LblTemp, intX)
          Next
    
       End Sub
    
    
       Private Sub PopulateLabelControls
    
          For intX = 0 to UBound(MyArray)
              CType(LabelCollection(intX),System.Windows.Forms.Label).Text = MyArray(intX)
          Next
    
       End Sub
    End Class
    That's a sparse example, you should be able to conform it to suit your needs.

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