Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to save a control's value to a mem file

Status
Not open for further replies.

waynebrady

Programmer
Feb 20, 2003
24
US
I'm using vfp 7.0. Is there a way to "globally" save the current values (thisform.pageframe1.page1.text3.value), of a control on a form, to a memvar file or a text file. I have a data entry form that has many many text boxes, check boxes, etc. and would like to save the values to a file. I'm trying to avoid saving each to a field in a table or storing each value to an individual memory variable and then saving to a mem file. I guess I'm just lazy and looking for a quick solution.

Thanks,


Wayne Brady
 
Yes, use SAVE TO and RESTORE FROM to save values in a Memo field. If you use the commands as is then you will save everything, including system variables. So I would suggest making sure that your controlsources are prefaced uniquely such as sv_MyVar1, sv_MyVar2. That way you can use the commands with a mask (see LIKE) and easily only save and restore the variables you want.

Slighthaze = NULL
craig1442@mchsi.com
"Whom computers would destroy, they must first drive mad." - Anon​
 
I personnally try to avoid .mem files. I have been burned in the past when variables have stomped on other variables. I prefer INI files.

Check out this faq to read/write to one.

how can I read and write to an inifile using API calls
faq184-2916

Jim Osieczonek
Delta Business Group, LLC
 
Slighthaze,
As far as I can tell, SAVE TO does not save any VALUES that are stored in controls. I tried using that originally, however it disregards anything identified as "thisform.text3.value" etc. It will only save memory variables and system variables.

Thanks,


Wayne Brady
 
Wayne,

I think what Slighthaze meant was this: If you use a naming convention for your contol source variables, you can use SAVE TO .... ALL LIKE <skeleton> syntax to save them (correct me if I am wrong, Slight).

For example, set the control sources to variables whose names begin with SV_. Then you can do:
SAVE TO MySaveFile ALL LIKE SV_*

Mike




Mike Lewis
Edinburgh, Scotland

My Visual Foxpro web site: My Crystal Reports web site:
 
Mike / Slighthaze,

Perhaps I wasn't clear on how I'm using the controls. I was trying to avoid setting up a &quot;control source variable&quot; for each control. In this instance, whenever I refer to an individual control's value I would spell out the whole &quot;thisform.text3.value&quot; instead of specifying the &quot;control source&quot;. I think that there is no quick solution...I'll just have to either assign each control a control source or store each control's value to a table.

Thanks,


Wayne Brady
 
Wayne:

If I'm reading this correctly, I think you could store all the values or control name and value to an array, then write the array to a file using a custom method and a for each loop. You could restore the values pretty much the same way.
 
MikeLewis, you hit the nail on the head as to what I was trying to say.

waynebrady, there are plenty of ways to do what you want to do. Kind of a manager of sorts that you want to White Box so it will work with any form. OhioBill has given somewhat the approach I would take...however I would still use Save to and Restore from to do it, because it would be easier I guess than writing to a file and such. If you ended up with a two dimensional array of the controls and their values ary_MyForm(1,1) = &quot;thisform.text1.value&quot; ary_MyForm(1,2) = &quot;Hello World&quot;, then you could easily loop through it and reset up your for whenever you wanted. Not totally different from going through the steps to setup controlsources and binding the controls to them, but I guess it could save you some time and be useful in certain situations.

As for loading the array, there are plenty of threads in this forum on looping through all the controls on a form, and you seem to be a fairly knowledgeable VFP programmer, so take a few of these ideas and put together a white box solution and post it back here so we can mess around with it. [smile] Sort of a settings manager of sorts, it could be expanded to use a table that would hold all of the values of every form in an application in a table with a form name field and a memo field for the mem info. Put together as a non-visual class that can be dropped on any form and does it's job. Might end up with something halfway neat in the end, then again it might prove to be a big old bomb...but only one way to find out.

Slighthaze = NULL
craig1442@mchsi.com
&quot;Whom computers would destroy, they must first drive mad.&quot; - Anon​
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top