Microsoft KB Archive/126952

= How to Scope a Variable to a Form =

Article ID: 126952

Article Last Modified on 2/12/2000

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q126952



SUMMARY
This article explains how to declare variables that exist and are visible throughout a form but are released when the form is released.



MORE INFORMATION
A variable declared in a method of a form is visible while the method is executing. Any reference to this variable after the method exits will yield a 'Variable not Found' error message. In Visual FoxPro, the Form Designer builds a Form class, and a Form is an object. Variables declared in a method such as the Init or Load are scoped to the method. A variable scoped to a Form object has to be a member variable, or property. This differs from the version 2.x model, where variables declared in the Setup of a screen would be generated at the beginning of the .SPR file, and be available to the program and procedures that the program calls.

Use the following steps to add a new property to a Form in the Form Designer:  Choose New Property from the Form menu. Type the name of the member variable, and click OK in the dialog. The property is now available at the bottom of the property sheet. To refer to the property from an object in the Form, you can:

 Use the This object reference at the Form level. For example:

This.chvar1

 Use the ThisForm object reference at the Object level. For example:

ThisForm.chvar2

 Use the name of the Form reference. For example:

Frmtest.chvar1

</ul> </li></ol>

Additional query words: VFoxWin screen private

Keywords: KB126952

-

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

© Microsoft Corporation. All rights reserved.