CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 1999
    Posts
    18

    How to know if a form has been loaded ?

    How can i know if one of the Form of the project has been loaded ?

    I tried someting like
    If MyForm Is Nothing Then ..
    but it dosen't work

    Thanks


  2. #2
    Join Date
    Sep 1999
    Posts
    17

    Re: How to know if a form has been loaded ?

    Are you using MDI forms or MDI child forms? If so, you can cycle through the forms collection to see if a specific form is loaded.

    'Here's some sample code
    Dim iIndex As Integer

    For iIndex = 0 To Forms.Count - 1
    If (Forms(iIndex).Name = "frmYourForm") Then
    MsgBox Forms(iIndex).Caption
    End If
    Next iIndex


  3. #3
    Join Date
    May 1999
    Location
    Omika, Japan
    Posts
    729

    Re: How to know if a form has been loaded ?

    Forms Collection is the best method.

    Because VB keeps a global instance of the Form (with the same name ). So -
    If MyFormName iS Nothing - will always be false, because there always exists a form by name 'MyFormName'. Typically what people do is not refer this Global form.

    You could do something like this also:
    dim lpForm as Form
    ...
    set lpForm = New MyFormName
    ..else where
    ' check if an instance is loaded:
    if lpForm Is nothing then
    Set lpForm = New MyFormName
    end if
    ' use the properties ..
    lpForm.SomeProperty = SomeValue



    RK

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

Featured