Microsoft KB Archive/126956

= How to Return a Value from a Form =

Article ID: 126956

Article Last Modified on 2/12/2000

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q126956



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:

129648 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
 Create a form and place a text box on the form.  Add a command button to the form. Place the following command in the Click method of the form. THISFORM.Release  Set the WindowType property of the form to Modal. Click New Property from the Form menu to add a Custom Property to the form. Call this property lRetVal.  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   Place the following command in the Unload method of the form: RETURN THISFORM.lRetVal   Call the form by using the following command: DO FORM MyForm TO lMyRetVal </li>  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) </li></ol>

Additional query words: VFoxWin

Keywords: KB126956

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.