Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Form with Public/local/private memory variables
Message
From
10/12/2000 11:24:28
Cindy Winegarden
Duke University Medical Center
Durham, North Carolina, United States
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00451344
Message ID:
00451349
Views:
22
David,

Don't make your variables public or private, make them properties of your form. Then they'll be available everywhere in the form, no matter which method you're in. In the load event you'll have code like THISFORM.MyProperty = MyValue.

But, if your memory variables are really just empty copies of the fields in your table, you really might want SCATTER NAME THISFORM.oMyProperty BLANK then assign your initial values.

You'll want the control source of the text boxes to be something like THISFORM.oMyProperty.MyValue.

Visual FoxPro 6 Enterprise Development by Paddock, Petersen, and Talmadge helped me a lot when I was learning this.



>I don’t know too much about memory variables, and only just a little about VFP programing.
>
>I have an application that has a main form, containing a pageframe with pages.
>
>My application works fine, but in the load event, I have all of my memory variables first declared as PUBLIC (Public, followed by all of the variable names). I then have initiated a number of them with initial values, eg store space (30) to myname, store 1 to m.qty. I have read that PUBLIC memory variables are not a good thing, and I am now trying to make the variables Private or Local.
>
>On one of the pageframes pages, I have a grid that “Scatters Memvars” to some text boxes. If the user ifs satisfied that this information is correct, the save button is clicked, and the information is “Gathered Memvar”. The textboxes are all set to m. variable field names. This all works fine when the memory variables are declared Public.
>
>But, if I try to declare these memory variables as Local, I get problems. The info scatters into the text boxes fine, and gathers fine. But when the save button tries to store some of the m. variables, it comes up with the error message eg. “cannot find prodcode” when the code gives a command such as “store m.prodcode to oldprodcode”.
>
>My recent understanding is that variables are automatically private when you define them. Eg in the load event of the form, I have code such as “store 1 to m.qty”. But when I run the form, and go to page where there is a spinner control with the control source set to m.qty, it shows up as 0 instead of 1. This is also the case with many other variables that I have set up with the store command.
>
>In another example, in the form’s load even I have placed a command “store space(6) to myvariable”. But when moving about the pages on the form, I get the error message “variable myvariable not found”. (This works fine however if I declare myvariable as PUBLIC at the start)
>
>It seem that many of these variables can’t be seen by the rest of the form, (unless I declare them as PUBLIC)
>
>I thought that Local and Private variables could be seem by the entire form. Any suggestions.
>
>Regards David
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform