[RESOLVED] Control Array - Loading
I have a Form with a Frame control array. Within each Frame are a number of other Controls, about 20 of them, which are also Control Arrays.
When loading a new Control within a given Frame, rather than type out 20 'Load' and other positioning statements etc., I thought of using a For / Next loop iterating thought the Controls collection of the Form. Here is the 'proof of concept':
Code:
Option Explicit
Private Sub Command_Click()
Dim ctl As Control
Load Frame(1)
Frame(1).Visible = True
Frame(1).Top = Frame(0).Top + Frame(0).Height
For Each ctl In Me.Controls
If ctl.Container.Name = Frame(0).Name Then
Load ctl(1)
Set ctl(1).Container = Frame(1)
ctl(1).Top = ctl(0).Top
ctl(1).Left = ctl(0).Left
ctl.Visible = True
End If
Next
End Sub
Private Sub Form_Load()
Set Text(0).Container = Frame(0)
Set Label(0).Container = Frame(0)
End Sub
Basically I have Frame(0) drawn of the Form and within that I have drawn the Text(0) and Label(0) Controls. On clicking Command it's meant to load elements Text(1) and Label(1).
The Frame loads fine but when it comes to loading the TextBox and Label I get an error: 344 "Must specify index for object array"
I've messed around with the Load statement but nothing I've tried has worked (yet)
Am I doing something incredibly stupid or is this one of those things that 'can't be done' like this ? (similar to trying to Unload a Control in an Click Event procedure) If so does anyone know of an alternative method?
Re: Control Array - Loading
try like
vb Code:
If ctl.Container.Name = Frame(0).Name Then
load me.controls(ctl.name)(1)
End If
ctl is already a member of the control array text1(0), not text1
Re: Control Array - Loading
Thanks, pete. I thought it was me rather than VB, couldn't see the wood for the trees :)
Re: [RESOLVED] Control Array - Loading
try this
Code:
If ctl.Container.Name = Frame(0).Name Then
Set obj = Me.Controls(ctl.Name)
Load obj(1)
Set obj(1).Container = Frame(1)
obj(1).Top = obj(0).Top
obj(1).Left = obj(0).Left
obj(1).Visible = True
End If
edited: Dim obj as Object