Hi
How can I termiante a program with a command (like "Exit" in Pascal or "Return" in C)
Thanks
Ehsan
Printable View
Hi
How can I termiante a program with a command (like "Exit" in Pascal or "Return" in C)
Thanks
Ehsan
To terminate your program brutally, you can use "End" statement. I do suggest you to not use this word, anyway, but to Unload all forms and dinamically added controls, and to set to nothing all references to objects and forms. Example:
unload form1
set form1 = nothing
Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
The Unload is not allways enough. The END statement definitely ends the program.
This is an example. You have Textbox, Command1 and Command2 buttons. Press Command2
and Do Loop begins, beeps once a second. Press Command1 to stop the program but it does not stop, it disappears but it beeps. So it is still running.
Private Sub Command1_Click()
Unload Form1
Set Form1 = Nothing
End Sub
Private Sub Command2_Click()
Dim a As Single, b As Single
a = Timer
Text1.Text = "Press Command1"
Do
b = Timer
DoEvents
If b - a > 1 Then
Beep
a = Timer
End If
Loop
End Sub
Hi
Thanks but i have some problems with unloading forms:
I have a form with an activex on it and when I call unload form I receive an application error:
The instruction at "..." refrenced memory at "...".
the memory could not be read
could u pls tell me What is the reason?
Thanks Ehsan
That is true, but it is a "dirty" end: you should stop your timer and exit loop before unloading: the process running will prevent your form from a truly unload...
Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
Look if this sounds familiar:
you have one form
you load the form from sub main
you have an activex on the form
you make the activex starts his job or you invoke a method or set a property of activex (or of the form) from somewhere else (not from sub main).
Then you (maybe even if job is finished) try to unload the form...
If you have declared something as "Public" in your form or activex,you can call it from everiwhere, but in the sametime, you will have a new reference to the object. You gain a new istance of object also when you use the "new" keyword
(ie: set myx = new controlX). You have to set all references to nothing, before you can unload your form.
Hope this was the matter.
Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
It might help if we knew what is the activex control that you're using and how are you using it.
-Cool Bizs