Am I missing something?? Do I have to manually unload every form or
something like that??
I was under the impression that VB called the EXIT method when CLOSE is
clicked (alt-f4)?????????
Please mail and post suggestions.
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
| Kevin D. Drucker | e-mail: dru...@cellerity.com (preferred) |
| Electronics Desn Engr | kddr...@amp.com (alternate) |
| Connectware, Inc. | voice: (215) 233-4674 fax: (215) 233-891 |
+-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
Kevin, there is no guarantee that an app will have a File/Exit. Every
VB form has an Unload Event though. I think this works and gets
called when the user does the System Close thing:
Form_Unload(Cancel As Integer)
End
End Sub
This isn't completely correct; you should probably test the Cancel
variable (comes from Form_QueryUnload, I think).
--
Greg Dainard e-mail: ge...@phoenix.net
Systems Analyst WWW: http://www.phoenix.net/~getj
Sub Form_Unload (Cancel As Integer)
' This code explicitly causes all application forms to unload when the
' user terminates the program. This keeps the application from leaving a
' form loaded in memory, which leaves the VB parent window open to the
' Task List.
Dim I
For I = 0 To Forms.Count - 1
Unload Forms(I)
Next I
End
End Sub
Don Clark
Sorry, this doesn't work, you get a "Subscript out of range"
error. Here is some tested code :-
Sub Form_Unload (Cancel As Integer)
Dim i As Integer
Dim f As Form
muloop:
For i = 0 To Forms.Count - 1
Set f = Forms(i)
If Not f Is Me Then
Unload f
GoTo muloop
End If
Next i
End Sub
----------------------------------------------
Andrew Cheshire an...@axiomati.demon.co.uk
Axiomatic Software CIS: 100273,154
"i forgive you molesworth for those uncouth words"
>Sorry, this doesn't work, you get a "Subscript out of range"
>error. Here is some tested code :-
>Sub Form_Unload (Cancel As Integer)
> Dim i As Integer
> Dim f As Form
>muloop:
> For i = 0 To Forms.Count - 1
> Set f = Forms(i)
> If Not f Is Me Then
> Unload f
> GoTo muloop
> End If
> Next i
>End Sub
The reason you get subscript error is because when you unload a form, the
forms.Count is reduced from what the loop is initialized to do. To elimate
this problem, simply loop backwards.
For I = Forms.Count - 1 to 0
>
> Sub Form_Unload (Cancel As Integer)
>
> Dim i As Integer
> Dim f As Form
>
> muloop:
> For i = 0 To Forms.Count - 1
> Set f = Forms(i)
> If Not f Is Me Then
> Unload f
> GoTo muloop
> End If
> Next i
>
> End Sub
A better solution is:
For i = Forms.Count - 1 To 0 Step - 1
If Not Forms(i) Is Me Then Unload Forms(i)
Next
The reverse count does the trick.
Jens
--
* Everything I said are the opinions of someone else. *
* I just cut-and-pasted. *
Jens Balchen jr.
bal...@oslonett.no
P.O.Box 6052
N-4602 Kristiansand