FoxPro form flashes on the screen and vanishes


Everybody meets this problem with their first executable; the program runs well in the development environment but fails when run from Windows. The FoxPro window just flashes on the screen and then vanishes. You can search VFP Help for terms like "flash", "vanish" and "disappear" but you will find nothing. The information is hidden away under "How to: Control the Event Loop" and you won't be able to ship your exe until you find it.

This problem crops up because Visual FoxPro is now an event-driven language. It runs through the code for your form, reaches the end, and the program terminates when there is nothing more to do. Everything vanishes from the screen. The same thing will happen if your application is based on a main menu; FoxPro will run through the code to create the menu, the menu will flash on the screen but then the program terminates and the menu vanishes.

The solution is a simple one once you realise what FoxPro is doing. You have to tell FoxPro to start its event-processing loops. The command that does this is:

Read Events

You'll need to add this code in different places depending on whether you are using a form, a menu or a program as the main element of your application.

If you are using a form then add this as the last line in the Activate event. This will allow the form to load and initialise itself before going into the event processing loop and waiting for mouse and keyboard events.

In a menu, add it to the CleanUp code snippet. Select General Options from the View menu then click the Cleanup... tick box. An edit window will open behind the dialog; click OK to close the dialog window and the CleanUp edit window will remain:

If you have a program as the main element of your project then add the line immediately after you have set up the user interface by loading a form or menu.

One last thing to remember

This will start the event processing loop but we need to stop the loop to close the application. Otherwise you'll hit the second most-common problem:

Use the Clear Events command to stop the event-processing loop. Execution will continue from the line following the Read Events command.

More details on this problem "); document.write("Site Search"); document.write("
"); document.write(""); document.write("
Go"); document.write(""); // -->

The Site Search feature requires JavaScript. If your browser does not support Javascript then please use our Site Map instead.


Hints & tips

The textbox class in Visual FoxPro 9 has a new Autocomplete property which shows the user the previous values that have been entered in that textbox.
Autocomplete in VFP 9

Your Access database will look more impressive if you add custom toolbars...
Custom toolbars

FoxPro has always had functions to read and write files at a low level...
Foxpro low level file functions

More...
More pages of hints and tips for users of Microsoft FoxPro and Access databases.

Site Map