Results 1 to 2 of 2

Thread: vbModal form used to unload forms and end?

  1. #1
    Rodney Cockrell
    Guest

    vbModal form used to unload forms and end?

    There are too many threads related to this topic, but none of them are specific to my example. I know how to close a program, but I want to check if my method is the most efficient.

    In all of my programs, I have this code in the main form:

    ----------------------------------------------------------------------

    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

    Dim frm As Form

    'Make sure everything is unloaded.
    For Each frm In Forms
    Unload frm
    Next

    End Sub

    ----------------------------------------------------------------------

    In a specific program I'm working on, I also include this code in the Form_QueryUnload to clean up the tray icon display:

    ----------------------------------------------------------------------

    t.cbSize = Len(t)
    t.hWnd = pichook.hWnd
    t.uId = 1&
    Shell_NotifyIcon NIM_DELETE, t

    ----------------------------------------------------------------------

    All of this works great. However, if I want to give the option to quit the program on another form (presented via frmMyform.Show vbModal), what is the best way to do that? I could just copy and paste all of the above into the frmMyForm form's Form_QueryUnload and change the Shell_Notify code to point to the primary form. Another option would be to have a global Boolean variable that gets set to True if the user chose the exit option from the frmMyForm form. For example:

    ----------------------------------------------------------------------

    frmMyform.Show vbModal
    if isItTimeToExit = True then Unload Me

    ----------------------------------------------------------------------

    I think either method would work, but can someone think of a more efficient way to exit?

  2. #2
    Fanatic Member rudvs2's Avatar
    Join Date
    Mar 2001
    Location
    NZ
    Posts
    935
    perhaps you could place all your unload code into a module then just call the subs from which ever form you need to

    just a thought

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