A Visual FoxPro .EXE file appears briefly, and then it exits to the
The main program is a screen or menu, and no READ EVENTS command has been
issued. In Visual FoxPro, the Command window provides a place for your
application to wait for the next command. Because the Command window is
unavailable in a run-time application, the .EXE file has no wait state to
anticipate keyboard input, so the application returns to the operating
A READ EVENTS command or a modal form will provide a wait state for your
This behavior is by design.
Adding a READ EVENTS to a menu
If the main program in your project is a menu, a READ EVENTS command should
be added to the menu as follows:
- In the Menu Builder on the View menu, click General options.
- Select the Cleanup check box. In the Cleanup code window, add this code:
- Add a Quit option to the menu that contains this command:
If the main program in your project is a form or formset, there are several
ways to proceed as described in the remainder of this article.
Creating a Modal Form or Formset
The easiest way to provide a wait state for a form or formset is to set the
WindowType property to 1 - Modal at design time.
This may be undesirable if you want to run other forms from within the
current form or formset.
Creating a Program that Issues a Read Events
The form or formset can be run from within a program that issues a READ
EVENTS. For example:
- Create a program containing this code:
DO FORM <formname>
- Save this program, and make it the main program in your project.
- Add a command button to the form. Add the following code in its Click
Adding a READ EVENTS to a form or formset
If you do not want to create a wrapper program that runs the form and
issues a read events command, you can add the appropriate code to the form
or formset itself. For example:
- Add a new property to the form or formset named RdEventsFlag. Set the
value of this property to false (.F.).
- In the Activate method of the form or formset, add this code:
THISFORM.RdEventsFlag = .T.
- Add a command button to the form. Add the following code to its click
Change THISFORM to THISFORMSET everywhere it appears if you are working
with a formset instead of a form.
Steps to Reproduce Behavior
- Create a quick form.
- Create a new project, and add the form to the Documents tab.
- Build an executable from the project.
- Exit Visual FoxPro, and run the executable. The menu appears briefly;
then the executable returns to the operating system shell.
Visual FoxPro Professional Features Guide, Chapter 9.