> try using
>
> END instead of unload me(if you want to close the application)
From an old post of mine...
Never, never, never, never, ever use the End statement to terminate your
program.
End should ***NEVER*** be used in VB. When you start writing more complex
code, you will find that in certain situations, VB needs to do some cleaning
up (and you need to help it). You can go to this Google newsgroup link
http://groups.google.co.uk/advanced_group_search?num=100&as_scoring=d&as_ugroup=*.vb*
and look up the exact word "vb" and the exact phrase "end statement" (leave
off the quotes in both of these) to find the many ways people have explained
the why and what of not using the End statement. Suffice it to say that the
End statement stops your program in the same way running into a brick wall
stops your car... immediately. You don't get a chance to coast to a stop and
turn your key to the off position, open the door and exit the vehicle. The
same thing happens with the End statement... BOOM!, everything stops dead in
its tracks right then and there and the program ends. The moral is... NEVER,
NEVER, NEVER use the End statement in your program! (And, in the same way,
using that "solid square" icon on VB's Toolbar, or clicking End in the Run
menu, to stop your project during development is the identical equivalent of
executing an End statement in code... you shouldn't do that either.)
Consider this... From the VB Help Files: "More About Forms"
"The End statement ends an application immediately: no code after the End
statement is executed, and no further events occur. In particular, Visual
Basic will not execute the QueryUnload, Unload or Terminate event procedures
for any forms. Object references will be freed, but if you have defined your
own classes, Visual Basic will not execute the Terminate events of objects
created from your classes."
"In addition to the End statement, the Stop statement halts an application.
However, you should use the Stop statement only while debugging, because it
does not free references to objects."
Rick
Martin Trump - 29 May 2006 16:28 GMT
Hi
>Never, never, never, never, ever use the End statement to terminate your
>program.
(VB6, Win 2k)
I try to follow the excellent advice given here but... the program
below won't terminate either by double clicking or closing the form
without an End statement.
============================
Private Sub Form_Load()
Dim i As Long, t As Single
Me.Show
For i = 1 To 100000
Me.Caption = CStr(i)
t = Timer
While (Timer - t) < 1
DoEvents
Wend
Next i
End Sub
Private Sub Form_DblClick()
Unload Me
'End seems to be required here!
End Sub
============================
I'd be grateful to learn the proper way. TIA
Regards

Signature
Martin Trump
Rick Rothstein - 29 May 2006 17:10 GMT
>>Never, never, never, never, ever use the End statement to terminate your
>>program.
[quoted text clipped - 23 lines]
>
> I'd be grateful to learn the proper way. TIA
Try disabling the Timer before unloading the form.
Rick
Martin Trump - 29 May 2006 18:20 GMT
>Try disabling the Timer before unloading the form.
Thanks for all responses. OK. I'm using the system Timer, not a Timer
control. I modified the Sub as below to:-
Private Sub Form_DblClick()
Timer.Enabled = False
Unload Me
'End seems to be required here!
End Sub
On double clicking I see:-
=================
Invalid qualifier
=================
What next? TIA.
Regards

Signature
Martin Trump
Rick Rothstein - 29 May 2006 18:38 GMT
>>Try disabling the Timer before unloading the form.
>
[quoted text clipped - 12 lines]
> =================
> What next? TIA.
Whoops! Sorry, I misread your code (for some reason, I thought you were
using a Timer control). Remove the line you just added... the Timer you are
referring to is a function and cannot be disabled. Take a look at Steve's
response to you... it looks like his answer might address your problem.
Rick
JaPoNoGo - 30 May 2006 15:03 GMT
I dont want to unload all form. I want to unload a form. Hide code isnt
usefull for me. When i use unload code, i cant see the form but the
form is running in background. when i want to close all form, i use
"End". Thanks in charge, Sorry for my English
Steve Gerrard - 29 May 2006 17:11 GMT
> Hi
>>Never, never, never, never, ever use the End statement to terminate your
[quoted text clipped - 26 lines]
>
> Regards
Wait 27.8 hours for the loop to finish, then double click :) ... or
Use a flag so the loop can bail out, and change it in the QueryUnload event:
Private mGo As Boolean
Private Sub Form_Load()
Dim i As Long, t As Single
mGo = True
Me.Show
For i = 1 To 100000
Me.Caption = CStr(i)
t = Timer
While mGo And (Timer - t) < 1
DoEvents
Wend
If Not mGo Then Exit For
Next i
End Sub
Private Sub Form_DblClick()
Unload Me
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
mGo = False
End Sub
Martin Trump - 30 May 2006 15:56 GMT
>Wait 27.8 hours for the loop to finish, then double click :) ... or Use
>a flag so the loop can bail out, and change it in the QueryUnload
>event:
Steve - many thanks. Another one to add to my increasing list of "I
wouldn't have thought of that in a thousand years".
Regards.

Signature
Martin Trump