|
-
Feb 2nd, 2004, 12:31 PM
#1
Thread Starter
Addicted Member
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:
for i=0 to ubound(array)
label(i).text=array(i)
next
Desired Results:
label1.text=43
label2.text=64
label3.text=87
etc.....
Cheers,
Bebandit
-
Feb 2nd, 2004, 03:03 PM
#2
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|