Results 1 to 5 of 5

Thread: [RESOLVED] ForEach confusing me. Shows Captions instead of Names?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    211

    [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?
    Last edited by DssTrainer; Feb 7th, 2007 at 04:35 PM.

  2. #2
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    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.
    CS

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    211

    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

  4. #4
    Frenzied Member cssriraman's Avatar
    Join Date
    Jun 2005
    Posts
    1,465

    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
    CS

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2006
    Posts
    211

    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width