I would like to create an array of labels. I would like to link these labels to an external data source. I believe the best way is to create a control array. How can I do this?
Printable View
I would like to create an array of labels. I would like to link these labels to an external data source. I believe the best way is to create a control array. How can I do this?
change this to labels.
Code:'add an option button to your form
'right click it and copy and then add
'you will be asked if you want an array..say yes
'delete the button you just added
'leaving the option button with index = 0 on the form
Option Explicit
Public MaxId As Integer
Private Sub option1_Click(Index As Integer)
Option1(0).Caption = "This is as good as it gets."
End Sub
Private Sub command1_Click()
MaxId = 4
Dim i
For i = 1 To MaxId
Load Option1(i) ' Create new button.
Option1(0).SetFocus ' Reset button selection.
' Set new button under previous button.
Option1(i).Top = Option1(i - 1).Top + 400
Option1(i).Visible = True ' Display new
' button.
Option1(i).Width = 4000
Option1(i).Caption = "Option" & i + 1
Next i
End Sub
'Option buttons are removed by the Click event procedure for the Delete command button:
Private Sub Command2_Click()
For i = 1 To MaxId
If MaxId < 1 Then Exit Sub ' Keep first buttons.
Unload Option1(i) ' Delete last button.
MaxId = MaxId - 1 ' Decrement button count.
Option1(0).SetFocus ' Reset button selection.
Option1(0).Width = 4000
Next
End Sub
To create the control array of labels, place a label on your form. Then copy and paste that label as many times as you want. VB will do the rest after you respond "Yes" to the "Do you want to create a control array?" question.
Thank you. Solved my problem. You're excellent dudes.