|
-
Jul 22nd, 2011, 03:04 AM
#1
[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?
-
Jul 22nd, 2011, 05:04 AM
#2
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
Last edited by westconn1; Jul 22nd, 2011 at 05:07 AM.
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 22nd, 2011, 05:43 AM
#3
Re: Control Array - Loading
Thanks, pete. I thought it was me rather than VB, couldn't see the wood for the trees
-
Jul 22nd, 2011, 05:56 AM
#4
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
Last edited by seenu_1st; Jul 22nd, 2011 at 06:03 AM.
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
|