|
-
Jul 15th, 2003, 01:40 PM
#1
Thread Starter
Hyperactive Member
Control array object from form Controls collection?
How can I access a control array object as an item on a form, vs. explicitly by name?
e.g. I have a TextBox "Text1", with index=0 on a form (that's it)
but the following code fails with Error 344, "Must specify index for object array"
Code:
Dim xx As Object
For Each xx In Me.Controls
Load xx(1)
Next xx
FWIW
Load Text1(1) works fine.
? TypeName(Text1) = Object
? TypeName(xx) = TextBox
Apparently, in the For Each loop it's giving me actual instances of the textbox control, rather than the control array itself.
Thanks, DaveBo
"The wise man doesn't know all the answers, but he knows where to find them."
VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15
-
Jul 15th, 2003, 01:41 PM
#2
Hyperactive Member
Re: Control array object from form Controls collection?
Originally posted by DaveBo
How can I access a control array object as an item on a form, vs. explicitly by name?
e.g. I have a TextBox "Text1", with index=0 on a form (that's it)
but the following code fails with Error 344, "Must specify index for object array"
Code:
Dim xx As Object
For Each xx In Me.Controls
Load xx(1)
Next xx
FWIW
Load Text1(1) works fine.
? TypeName(Text1) = Object
? TypeName(xx) = TextBox
Apparently, in the For Each loop it's giving me actual instances of the textbox control, rather than the control array itself.
Thanks, DaveBo
Modify ur code thus:
Dim xx As Object
For Each xx In Me.Controls
Load xx(1)
Next xx
-
Jul 15th, 2003, 01:42 PM
#3
Hyperactive Member
Re: Re: Control array object from form Controls collection?
Originally posted by apps_tech
Modify ur code thus:
Dim xx As Object
For Each xx In Me.Controls
Load xx(1)
Next xx
sorry before i enter the code it got submitted. here is the one i wanted to write:
Dim xx As Object
For Each xx In Me.Controls
If typeof(xx) is textbox then
Load xx(1)
end if
Next xx
i guess it should work...
-
Jul 15th, 2003, 02:03 PM
#4
Thread Starter
Hyperactive Member
Not quite
It is a textbox, and that seems to be the problem.
If you put a regular textbox, Text1 on a form
and then a 2nd, Text2, with index=0.
Then compare the properties/methods of Text1 and Text2, you'll see that Text2 (without the (0) index specified) looks more like a collection.
Thanks, DaveBo
"The wise man doesn't know all the answers, but he knows where to find them."
VBForums is one place, but for the really important stuff ... here's a clue 1Tim3:15
-
Jul 15th, 2003, 02:45 PM
#5
PowerPoster
You can't access a control array from the Forms Control collection. You can get the controls atributes for example Name,BackColor,Text etc...
VB Code:
Dim xx As Control
For Each xx In Me.Controls
If TypeOf xx Is TextBox Then
MsgBox xx.Name
MsgBox xx.Text
MsgBox xx.BackColor
End If
Next
but you can't access that controls collection properties such as xx.ubound or xx.count etc... which means you can't load another control.
For instance this won't work
VB Code:
Dim xx As Control
For Each xx In Me.Controls
If TypeOf xx Is TextBox Then
Load xx.Name(1)
End If
Next
Even though it is saying Load Text1(1) it still won;t work because you are looping thru the Forms control array and not the controls array itself.
Atleast that's what I think! I could be totaly wrong!
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

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
|