[RESOLVED] ForEach confusing me. Shows Captions instead of Names?
Hi,
I'm trying my luck with For Each control array logic and I'm confused as to why VB is returning the caption for the control, instead of the name(index)
Here is my code:
Code:
Dim daCtrl As Control
For Each daCtrl In frmMain.Controls
If TypeOf daCtrl Is ComboBox Then
msgbox daCtrl.Container
end if
Next
now the Container for the first 5 controls is a frame with the name of "Frame_Orders". The caption for that frame is "<Orders>"
The msgbox shows "<Orders>" But I am not asking for the Container.Caption value, I want the actual object name. It would seem almost obvious that VB would return the object name but apparently not. How do I get it to return the name instead of the caption?
Re: ForEach confusing me. Shows Captions instead of Names?
It's because the default property for that control is caption not name
like:
for label the default property is caption
for textbox the default property is text
etc.
Re: ForEach confusing me. Shows Captions instead of Names?
hmm I tried
Code:
If TypeOf daCtrl Is ComboBox Then
msgbox daCtrl.Container.Name
end if
not expecting it to work.. but it did.
Why would it default to the caption? Also it defaults to the current text value of the combobox as well, instead of the name.
Odd but I guess resolved
Re: [RESOLVED] ForEach confusing me. Shows Captions instead of Names?
It is the behaviour of the vb. we cannot change that.
for combo box the default property is text property. that's why
Re: [RESOLVED] ForEach confusing me. Shows Captions instead of Names?
ya i saw your initial post after my second one.. Thanks for the clearing up!