How to Return a Value from a Form

Last reviewed: April 30, 1996
Article ID: Q126956
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0

SUMMARY

This article describes a way to obtain a return value from a Form called with a DO FORM command.

MORE INFORMATION

Some operations require a return value from a Form. For example, a dialog box typically returns an answer from user input. The DO FORM command is used to instantiate a form designed with the Form Designer. The TO clause of the DO FORM command allows to specify a return variable. For example:

   DO FORM frmtest1 TO cOkvar

This statement returns a value to the cOkvar variable if a RETURN statement is placed in the Unload method of a Form and the form is modal (WindowType=1-Modal).

For more information about the DO FORM command, search using DO FORM in the FoxPro Help system.

For information on calling a form as if it were a function, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q129648
   TITLE     : Calling a Form as If It Were a Function to Return a Value

The following step-by-step example illustrates how you can use a property to hold the return value of a form.

Step-by-Step Example

  1. Create a form and place a text box on the form.

  2. Add a command button to the form. Place the following command in the Click method of the form.

         THISFORM.Release
    

  3. Set the WindowType property of the form to Modal.

  4. Click New Property from the Form menu to add a Custom Property to the form. Call this property lRetVal.

  5. In the Click method of the command button, store the value of the text box to the lRetVal property.

          THISFORM.lRetVal = THISFORM.Text1.Value
          *-- 'text1' refers to the text box
    

  6. Place the following command in the Unload method of the form:

          RETURN THISFORM.lRetVal
    

  7. Call the form by using the following command:

          DO FORM MyForm TO lMyRetVal
    

  8. Type a value in the text box, and close the form. To verify the return value type the following command in the Command window.

          = MessageBox(lMyRetVal)
    


Additional reference words: VFoxWin 3.00
KBCategory: kbtool
KBSubcategory: FxtoolFormdes


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: April 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.