|
-
Jan 22nd, 2007, 09:02 AM
#1
Thread Starter
Frenzied Member
Control Array in VBA
I may be missing something very obvious here, and I have been away from programming for a couple of years, but I can't seem to create a control array, either textboxes or labels etc.
When I copy and paste they come out as TextBox2 TextBox3 etc
Is there an obvious answer here?
(I expect so, but I can't find it )
-
Jan 22nd, 2007, 09:28 AM
#2
Re: Control Array in VBA
VBA question moved to Office Development
Are you using Excel? Word? Access? Which VBA platform are you developing with?
-
Jan 22nd, 2007, 09:31 AM
#3
Thread Starter
Frenzied Member
Re: Control Array in VBA
I am using Excel, sorry about that. :-)
-
Jan 22nd, 2007, 09:54 AM
#4
Frenzied Member
Re: Control Array in VBA
Is there an obvious answer here?
Sure: You can't.
You could get close to a control array but it would require a lot of repetitive code to do so.
VB Code:
Private Text(2) As TextBox 'an array so we can address the controls by index
Private Sub Init 'run this at the start of the program to fill the array
Set Text(1) = Text1
Set Text(2) = Text2
End Sub
Private Sub TextChange(Index As Long) 'the master change sub for a textbox, it is told the index of the textbox
MsgBox Text(Index).Text
End Sub
Private Sub Text1_Change() 'catch the change event of a control
TxtChange 1 'and send it to the master change sub, along with the controls index
End Sub
Private Sub Text2_Change()
TxtChange 2
End Sub
-
Jan 22nd, 2007, 10:21 AM
#5
Thread Starter
Frenzied Member
Re: Control Array in VBA
Thanks - seems a bit stupit that VBA doesn't allow arrays though.
Ah well, not that much of a problem.
Thanks for the option you suggested.
-
Jan 22nd, 2007, 10:35 AM
#6
Re: Control Array in VBA
Have a look at my post here on creating an event handler in VBA. It will give you a good approxamation of a control array.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
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
|