Results 1 to 6 of 6

Thread: Checking for instance of form. [SOLVED]

  1. #1

    Thread Starter
    Fanatic Member cpatzer's Avatar
    Join Date
    Sep 2004
    Posts
    537

    Question Checking for instance of form. [SOLVED]

    Hi,

    I have a form in an MDI application called viewer. It is used to display images. This form gets opened and closed all the time. I want to know if there is anyway to interrogate whether or not the form "instance" exists?

    I have tried IsNothing and some others with no luck.

    The way I am doing it now is with a "tracking variable". Basically I have a Boolean variable named viewerVisible in the MDI parent, when the MDI parent opens the instance it sets it to True, when the viewer closes it sets it to False.

    Is there a better way of doing this? It just seems wrong/sloppy.

    Thanks
    Last edited by cpatzer; Sep 15th, 2004 at 12:20 PM.

  2. #2
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    How about if you iterate through the parent's MDI children, and check to see if TypeOf the child form(s) is your viewer?

  3. #3

    Thread Starter
    Fanatic Member cpatzer's Avatar
    Join Date
    Sep 2004
    Posts
    537
    I guess I could do that... But wouldn't that be slower?

  4. #4
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690
    I guess it would be slower, but in practice, I bet the user wouldn't notice. You can always exit your iteration once you find the first instance also. I think it would be cleaner, though, because you're actually looking to see if an instance exists, rather than checking the status of some variable.

  5. #5

    Thread Starter
    Fanatic Member cpatzer's Avatar
    Join Date
    Sep 2004
    Posts
    537
    True dat. Thanks

  6. #6

    Thread Starter
    Fanatic Member cpatzer's Avatar
    Join Date
    Sep 2004
    Posts
    537
    Worked awesome!!!


    Code:
            Dim child As Form
            For Each child In MdiChildren
                If TypeOf (child) Is viewerForm Then
                    Exit Sub
                End If
            Next
            'if we get this far we don't have a viewer form
            viewer = New viewerForm
            viewer.MdiParent = Me
            viewer.MainForm = Me
            viewer.Show()

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