Page 1 of 1

Save variables

PostPosted: Sat Sep 10, 2011 1:46 am
by smartmedia
Hi..

So far SaveVariables command saves all active variables into file. Is possible to save only the variables you want..??? Like the ClearVariables do, separated by coma.

This way you can use the method as a parameter storage without using Registry or INI files.

Thanks

PostPosted: Sat Sep 10, 2011 4:27 am
by Gaev
smartmedia:

As long as you don't need to specify Variables to be Saved via a mask (e.g. abcd* or p?qrs) ... and you are prepared to specify each element of an Array Variable, here is a solution ...
Code: Select all
... populate some variables
SetVar "[abc]" "value of abc"
SetVar "[xyz]" "value of variable xyz"
SetVar "[First Name]" "content of First Name"
... setup parameters and call the routine
SetVar "[SaveVariables]" "abc,xyz,pqr4567,First Name"
SetVar "[SaveVariablesFile]" "!mySaves1.txt"
GoSub "SaveVariables"
... verify what was saved
FileRead "[SaveVariablesFile]" "All" "[SaveVariablesResult]"
AlertBox "File Content" "[SaveVariablesResult]"
... you can further reduce the 3 lines ...
Code: Select all
... setup parameters and call the routine
SetVar "[SaveVariables]" "abc,xyz,pqr4567,First Name"
SetVar "[SaveVariablesFile]" "!mySaves1.txt"
GoSub "SaveVariables"
... needed to trigger this ... to one line by converting the SubRoutine to a Function that can be called with a command like ...
Code: Select all
Call "gkSaveVariables" "[SaveVariables]" "[SaveVariablesFile]"


Here is the SubRoutine code ...
Code: Select all
:SaveVariables
... uses [SaveVariables] and [SaveVariablesFile]
FileExists "[SaveVariablesFile]" "[SaveVariablesFileExists]"
If "[SaveVariablesFileExists]" "=" "True"
   FileErase "[SaveVariablesFile]"
EndIf
StrParse "[SaveVariables]" "," "[SaveVariablesList]" "[SaveVariablesCount]"
Loop "1" "[SaveVariablesCount]" "[SaveVariablesCurrent]"
  SetVar "[SaveVariablesName]" "[SaveVariablesList[SaveVariablesCurrent]]"
  SetVar "[SaveVariablesValue]" "[[SaveVariablesName]]"
  If "[SaveVariablesValue]" ">" ""
     FileWrite "[SaveVariablesFile]" "Append" "[SaveVariablesName]=[SaveVariablesValue]"
  EndIf
EndLoop

Return

PostPosted: Sat Sep 10, 2011 5:19 am
by smartmedia
Hi..

The reason i suggest it is to make our life simple. I can do it with 10 different ways, registry - INI - FileWrite - Database.

Thanks any way for your suggestion.

PostPosted: Mon Sep 12, 2011 11:05 am
by Neosoft Support
So far SaveVariables command saves all active variables into file. Is possible to save only the variables you want..??? Like the ClearVariables do, separated by coma.


That's a good idea - I'll add it to our list. In the mean time, I think (as Gaev suggests) you should be able to do something similar with a subroutine or function.

PostPosted: Tue Sep 13, 2011 8:21 am
by dec
Hi,

I like the suggestion so put an "npSaveVariables" action into the npUtil plugin.

Thanks!