Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / May 2006



Tip: Looking for answers? Try searching our database.

Unload Me

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JaPoNoGo - 27 May 2006 14:41 GMT
when i want to close my form. I use "Unload Me" code. But sometimes it
runs in backgroung. How can i close it without close all form.
Veign - 27 May 2006 17:17 GMT
What else is happening on the form?

Make sure all timers are stopped and objects are cleaned up.

Signature

Chris Hanscom - Microsoft MVP (VB)
Veign's Resource Center
http://www.veign.com/vrc_main.asp
Veign's Blog
http://www.veign.com/blog
--

> when i want to close my form. I use "Unload Me" code. But sometimes it
> runs in backgroung. How can i close it without close all form.
c++ newbie - 29 May 2006 05:56 GMT
try using

END instead of unload me(if you want to close the application)

or else use

me.hide if you want to unload the form

but this is not the appropriate method to do it but works 9 out of  10
times.
Rick Rothstein - 29 May 2006 06:12 GMT
> 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

Mike - 29 May 2006 11:35 GMT
>when i want to close my form. I use "Unload Me" code. But sometimes it
>runs in backgroung. How can i close it without close all form.

Although I tend to use Me.Hide, followed by Unload Form, I had a similar
problem because I was looping in the Form_Load event.  Using a timer
instead cured the problem

Signature

Mike

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.