Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Control Arrays -- passing controls as a variable

Status
Not open for further replies.

TheComputerDude

Programmer
Feb 27, 2006
14
0
0
US
I have 3 control arrays (text box, list box, and combo box)and would like to populate a form in 3 columns. I have never tried to use a control variable before and I am have a problem trying to get it to work. My code is below, if you have any suggestions, please let me know.

Private Sub Form_Load()
Const intSpacing As Integer = 105
Dim intCounter As Integer
Dim ctrlName As Control

For intCounter = 1 To 2
Set ctrlName = lblCoverageType(0)
Load ctrlName(intCounter)
With ctrlName(intCounter)
.Left = ctrlName(intCounter - 1).Left + ctrlName(intCounter - 1).Width + intSpacing
.Visible
End With
If intCounter < 2 Then
End If
Next intCounter
End Sub
 
I think I see what you're up to. You're on the right track. Now:

1. In design mode, put a text box, a list box, and a combo box. Make them invisible.
2. When you load the form, store the left property of each control to its own module level variable. Set up a spacing constant as you have done, if you like.
3. When you add your first row of controls, just make the existing controls visible.
4. Create a Sub to add a subsequent row of controls. In this sub, just load each of your three controls. Use the left variables and the spacing constant.

<Set ctrlName = lblCoverageType(0)
Do not confuse the name of the control, which is a string, with the control itself, which is an object reference. What you're actually doing here is referencing your label control. For example, if you put
Code:
Set ctrlName = lblCoverageType(0)
ctrlName.Caption = "Hello World!"
then the first member of your lblCoverageType control array would now say "Hello World!". I have the feeling this is not what you're trying to do here.

If there's anything you don't understand here, post back.

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top