Microsoft KB Archive/196086

= PRB: ControlSource Variables not Visible until Text Box Selected =

Article ID: 196086

Article Last Modified on 5/12/2003

-

APPLIES TO


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

-



This article was previously published under Q196086



SYMPTOMS
If you base the ControlSource of a text box on a private or local memory variable and is the text box is populated before the form runs, then the variable is not visible to the methods or events of the form and its components until you select the text box by either clicking the text box or tabbing to the text box.



CAUSE
When the form is first instantiated, the memvars are still in scope. After the form has fully instantiated, the .prg file continues and ends, releasing the memvars. You can still see the values in the text boxes because the values were read before the memvars went out of scope. When you click the text box, it tries to refresh from the Controlsource. However, the Controlsource memvar does not exist, so the text box creates the memvar, and stores the current text box value in that memvar.



RESOLUTION
Following are two workarounds:

  Place a READ EVENTS after calling the form as follows: CLEAR ALL USE MyTbl SELECT MyTbl SCATTER MEMVAR DO FORM MyFrm READ EVENTS -or-  Declare the memory variable as public.



STATUS
This behavior is by design.



Steps to Reproduce Behavior
  Create and populate a table as follows: CREATE TABLE MyTbl (Fld1 C(2), Fld2 n(2), Fld3 n(2), Fld4 n(2)) INSERT INTO MyTbl Values ("aa",1,1,1) INSERT INTO MyTbl Values ("bb",2,2,2)   Create a form, MyFrm, and add a command button to it with the following code in the Click event: M.Fld4 = M.Fld2 + M.Fld3 </li> Add four (4) text boxes Text1, Text2, Text3, and Text4 to the form. Set the ControlSource for each of the text box controls to M.Fld1, M.Fld2, M.Fld3, and M.Fld4 respectively. Save the form.</li>  Create a program file (.prg) with the following code: CLEAR ALL USE MyTbl SELECT MyTbl SCATTER MEMVAR DO FORM MyFrm </li> Run the program created in step 4.</li> When the form opens, note that all the values for the text boxes display correctly.</li> Click the command button, and you the following error occurs:

Variable Fld2 is not found.

</li> Select Ignore and then close the form.</li> Repeat step 5 and click Text2 when the form opens. Clicking the command button does not produce any errors for Fdl2 but you now get this error:

Variable Fld3 is not found.

</li> Select ignore and close the form.</li> Repeat step 5. When the form displays, click Text2 and then click Text3. Now, clicking the command button does not produce the error(s).</li></ol>

Keywords: kbcontainer kbprb kbctrl KB196086

-

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

© Microsoft Corporation. All rights reserved.