Hi,
I am just a VB beginner. The following is 2 basic questions:
In vb6, how to generate an exe file? I select standard exe type in
project selection but I cannot see the exe in the project directory.
Besides, how to exit the main program in VB? I have tried the following
keywords but cannot succeed:
terminate, close, exit, bye
Thanks!
Dag Sunde - 30 Jun 2005 08:30 GMT
> Hi,
>
> I am just a VB beginner. The following is 2 basic questions:
>
> In vb6, how to generate an exe file? I select standard exe type in
> project selection but I cannot see the exe in the project directory.
[File] --> [Make projectname.exe...]
You will be asked where to save the exe.
> Besides, how to exit the main program in VB? I have tried the following
> keywords but cannot succeed:
>
> terminate, close, exit, bye
Unload Me, on the main form.

Signature
Dag.
J French - 30 Jun 2005 08:37 GMT
>Hi,
>
[quoted text clipped - 7 lines]
>
>terminate, close, exit, bye
File Make xxx.exe
To terminate from a main Form use: Unload Me
There are a few ramifications if you have more than one Form
displaying, but let's keep things simple for now.
There is a command called 'End'
/Never/ use it - it should not be in VB5 or VB6
- it is lethal
Mike Williams - 30 Jun 2005 09:25 GMT
> I am just a VB beginner . . . how to exit the main program in VB?
You've already had answers to your questions, but just to add a little note
you'll find that it is not usual to "exit the main program" at all for many
of the VB execs that you create. Have a look at most of the applications
that you use on your own computer (the Calculator, your word processor, your
newsreader program, a wav file editor, a graphics or drawing program, a disk
copier, etc, etc). Those applications (execs) do not end at all until the
*user* decides to end them (usually by pressing the little close button at
the top right of the window). If there is something specific that you want
your VB exec to do when the user does decide to end the program (write high
score tables to disk in a game for example) then you should place your code
that does that job in the main Form's QueryUnload event (if your app has a
Form, that is). The code in that event will be executed whenever your
program shuts down, for whatever reason (unless you use the "dreaded" End
statement in your own code, which Jerry has already quite rightly told you
*never* to use).
Mike
Ross - 30 Jun 2005 10:03 GMT
> the "dreaded" End
Another thing I've not heard of. What's so bad about end?
Dag Sunde - 30 Jun 2005 10:11 GMT
> > the "dreaded" End
>
> Another thing I've not heard of. What's so bad about end?
As Mike gave a clue to...
The cleanup code in the Form_QueryUnload() event will not run.
The program make a dead stop in its track. No cleanup-code is run,
no objects or memory is released, no files are flushed or closed.
"End" is just like pulling the plug of the computer for that particular
program.

Signature
Dag.
Ross - 30 Jun 2005 10:58 GMT
> > > the "dreaded" End
> >
[quoted text clipped - 8 lines]
> "End" is just like pulling the plug of the computer for that particular
> program.
Ahh, and to think. This is the accepted way they teach you in college now.
Ross
Rick Rothstein - 30 Jun 2005 13:35 GMT
> > the "dreaded" End
>
> Another thing I've not heard of. What's so bad about end?
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 - MVP