Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.

  Ken Murphy
  Where is Ken Murphy?
 Ken Murphy

About once every week or so, a beginner will post a question asking how to make their EXE work. When the application is run in the development IDE, it works like a charm, but when it is compiled into an EXE it seems to flash and dissapear.

Lets begin with the "Flash and Disappear" thing. VFP is like any other programming language - it starts running at the first line of code and runs through to the final line of code. This is what happens when your app "Flashes and Disappears." Lets assume you have a Main.Prg that goes like:

DO MyMainMenu.MPR

Your program goes through each line in turn. It starts by setting safety and echo off and does what ever other setup commands you have. It then runs MyMainMenu. So far so good, but when it completes running the main menu, it has nothing left to do (it has completed your Main.Prg) so it shuts down.

OK, so how do I fix it? You need to add a single line of code - READ EVENTS - right after the menu call.

Go into one of your forms, right click anywhere on the form, and select "Properties" from the popup menu. Now, take a look at the Methods tab and you will note that some of the items on the methods page have a small "lightning bolt" icon. These are "Events" and include things like the .Click() event, the .DblClick() event, the InteractiveChange() event, etc. When you issue a READ EVENTS command, you are basically asking VFP to start listening for these events. Now, when you run your main.prg it will run to the READ EVENTS command and it will stop and wait for user input - the selection of a menu item. This will solve your "Flash and Disappear" problem.

There is one proviso however. If you are going to tell VFP to READ EVENTS, you also need to tell it to stop reading the events. You do this with a CLEAR EVENTS command. Typically, you would place the CLEAR EVENTS command in a "Quit" menu item. For example, you would have a menu item like File->Exit or File->Quit and that menu item would issue the command CLEAR EVENTS. When the user selects this option, VFP stops listening for events and because the READ EVENTS command is the final line of code, it will have completed your Main.Prg and it will shut down.

Hope this helps.


Saifuddin K Hussain @ 12/18/2006 9:22:49 AM
Thanks Mr.Ken

Suppose I have a login form and I am not calling mainmenu.mpr from there. After login and password it calls another form (mainmenu.scx) in that form I put the command in the init event "do '\menu\mastermenu.mpr' with this, .T."
and then as advised by you I put Read Events.
After compling the same problem persist.

Am I missing something to follow you?


Ken Murphy @ 12/18/2006 2:27:59 PM

The FAQ was based on a typical VFP app where the mainmenu is an MPR file running in _Screen. Yours is slightly different.

If you are using a splash screen or a password screen, make these forms modal (you don't need a READ EVENTS for a modal form.) Now, call your MainMenu form and directly after the form call, issue a read events. Don't forget to issue a CLEAR EVENTS somewhere in your MainMenu form.


Saifuddin K Hussain @ 12/19/2006 8:48:43 AM
Thanks a lot Mr. Ken.
It really solve my problem.


reteece rhu salubre @ 8/10/2007 1:42:55 AM
I am a newbie. I did not use the .mpr as my main menu, instead I use another form .scx as my main menu. when I compile it says "not an object" how to make my form as an object?

My purpose to have a different menu is that I want to display a logo in that white blank area in my menu. I can do it in a form. How do I do it in an .mpr?

ganesh menoka @ 3/13/2008 1:50:19 PM
Thanks Mr.Murphy. I am beginner and I could not make my startup screen stay on window. I was missing 'READ EVENT'

edwin ibo @ 3/17/2008 2:07:25 AM
good day!

dear mr. ken,

i am a newbie. i followed what you ha've said(read events & clear events) and still i don't have anything.but when i run the programm(do myfirst.prg) in the vfp9 envi. it work fine.

what i am missing?
please advice.

more thanks!

Kannan @ 4/6/2008 10:28:14 AM
Please help me where to provide clear events to avoid such probem. It works find after build and run. It does't work when run seperately

anand kulkarni @ 5/28/2008 2:42:19 PM
i am anand from india
i have same problem while building .exe in vpf9. i have seen all your answers for buliding .exe in vfp9 and still i have the same problem . my code is as under

**** do setmain.prg code
set talk off
set stat off
* where all dbfs [ i am useing free table consept ] are opened
do idex
do form login_pass.scx
read events

*************** end of the setmain.prg

the login_pass.scx is opened
inpute login id and passwrd
click on OK cmdbutton
if above information [ login id and password is ok ]
it opens main.mpr .t.
above is my code but still i have same problem

Diovannie Donayre @ 6/11/2009 3:25:25 AM
CAn i set the menu as my main form?

Your Name: 
Your Feedback: 

Spam Protection:
Enter the code shown: