Microsoft KB Archive/132697

= PRB: Application Appears Then Exits to Operating System =

Article ID: 132697

Article Last Modified on 11/17/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q132697



SYMPTOMS
A Visual FoxPro .EXE file appears briefly, and then it exits to the operating system.



CAUSE
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 system.



RESOLUTION
A READ EVENTS command or a modal form will provide a wait state for your application.



STATUS
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: READ EVENTS   Add a Quit option to the menu that contains this command: CLEAR EVENTS 

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 READ EVENTS </li> Save this program, and make it the main program in your project.</li>  Add a command button to the form. Add the following code in its Click event: CLEAR EVENTS THISFORM.RELEASE </li></ol>

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.).</li>  In the Activate method of the form or formset, add this code: IF !THISFORM.RdEventsFlag READ EVENTS THISFORM.RdEventsFlag = .T.     ENDIF </li>  Add a command button to the form. Add the following code to its click event: CLEAR EVENTS THISFORM.RELEASE </li></ol>

Change THISFORM to THISFORMSET everywhere it appears if you are working with a formset instead of a form.

Steps to Reproduce Behavior

 * 1) Create a quick form.
 * 2) Create a new project, and add the form to the Documents tab.
 * 3) Build an executable from the project.
 * 4) Exit Visual FoxPro, and run the executable. The menu appears briefly; then the executable returns to the operating system shell.

<div class="references_section">