It is possible to add controls dynamicly to a form, but can you dynamicly add a controlarray (cf. label(..)) (or members of it) to a form too ?
Printable View
It is possible to add controls dynamicly to a form, but can you dynamicly add a controlarray (cf. label(..)) (or members of it) to a form too ?
Code:'this example uses option buttons but you can adjust
'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