Microsoft KB Archive/138680

= How to Scope Variable Declared in Event Code =

Article ID: 138680

Article Last Modified on 2/10/2000

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition

-



This article was previously published under Q138680



SUMMARY
A variable declared in event code is not visible outside that code unless the variable is declared Public or you crate a new form property.



MORE INFORMATION
Variables declared in event code for objects are only visible to those objects at the time the event code is running. There are two ways to make variables visible to code outside a specific event.

Method One
Declare the variable Public. To do this, add the following line of code to the Load event of your form: Public X

Method Two
Create a custom property of the form. To do this, follow these steps:

 Create a form. On the Form menu, click New Property. In the Name box, type X . On the Other tab of the form's Property sheet locate your new property (X), and select it. Type the words, Hello World, and press ENTER. Add a command button to your form.  In the Click event of the command button, enter the following line of code: WAIT WINDOW THISFORM.X                       </li> Run your form.</li> Click the command button. The wait window displays: Hello World.</li></ol>

Step-by-Step Example
<ol> Create a form.</li>  In the Load event of the form, add the following line of code: X = "Hello World" </li> Add a command button to your form.</li>  In the Click event of the command button, add the following line of code: WAIT WINDOW X An error occurs that states: Variable 'X' is not found. </li></ol>

Additional query words: VFoxWin

Keywords: KB138680

-

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

© Microsoft Corporation. All rights reserved.