Results 1 to 11 of 11

Thread: [RESOLVED] [2005] Testing whether a control exists

Threaded View

  1. #6
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [2005] Testing whether a control exists

    Quote Originally Posted by warrenayen
    VB Code:
    1. For X = 0 To fromForm.Controls.Count - 1
    2. If fromForm.Controls(X).ToString = "DropDownMessage.DropDownMsg" Then
    3. fromForm.Controls(X).Dispose()
    4. Exit For
    5. End If
    6. Next

    That's what I did. I created a nifty control that does drop down messages from the bottom of another control. To check if it exists, I check that it's type (to string) = "whatever" and leave the loop when done...

    fromForm is the form...BTW...
    VB Code:
    1. If TypeOf(fromForm.Controls(X)) Is DropDownMessage.DropDownMsg
    would probably be better than checking against a string value. If the name every changes, this method would cause a syntax error and let you know right away. Using a string comparison leaves room for error.

    This just goes for your example code, as far as the original thread poster, I would also do what RobDog suggested.
    Last edited by kleinma; Oct 27th, 2006 at 03:21 PM.

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