HP Forums
Saving data that you do not want wiped - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Saving data that you do not want wiped (/thread-7726.html)



Saving data that you do not want wiped - Han - 02-05-2017 11:35 PM

Nothing out of the ordinary here; just sharing a snippet of code on how to use AFiles() to save options that you don't want reset even if you need to modify your source on (on-calc). This only makes sense in an app program. Each time an option is changed, save it with ssSaveOptions(). Use ssLoadOptions() to restore the data. This can be placed inside an initializing program ssInit() that all routines would call.

PHP Code:
ssUserFile:="filename.dat";

// variables that will get wiped when the source is edited
ssSaveMode;
ssMaxIter;
ssFtol;
ssdxtol;
ssAutoVar;
ssWarning;
ssInit;


ssSaveOptions()
begin
  AFiles
(ssUserFile):={ ssSaveModessMaxIterssFtolssdxtolssAutoVarssWarningssMarkLimit };
end;


ssLoadOptions()
begin
  local l
:={};
  
local n;
  if 
pos(AFiles,ssUserFilethen
    l
:=AFiles(ssUserFile);
    if (
size(l) == 7then
      
for n from 1 to 7 do
        if 
type(l(n)) then return(0); end;
      
end;

      
ssSaveMode:=min(max(ip(l(1)),1),3); // require the value be integer from 1 to 3
      
ssMaxIter:=max(ip(l(2)),1); // must be integer and at least 1

      
ssFtol:=max(l(3),0); // must be non-negative
      
if (ssFtol == 0then ssFtol:=1e-9end// and greater than 0; use default if not positive

      
ssdxtol:=max(l(4),0); // must be non-negative
      
if (ssdxtol == 0then ssdxtol:=1e-9end// and greater than 0; use default if not positive

      // only allow 0 or 1
      
if ( (l(5) == 0) OR (l(5) == 1) ) then
        ssAutoVar
:=l(5);
      else
        
ssAutoVar:=0;
      
end;

      
// must be an integer from 1 to 3
      
if pos({1,2,3},l(6)) then
        ssWarning
:=l(6);
      else
        
ssWarning:=0;
      
end;

      
// make an integer; at least 1
      
ssMarkLimit:=max(1,ip(l(7)));

    
end;
  
end;
end;


ssInit()
begin
  
if ssInit then return(0); end// if already initialized, do nothing
  
ssLoadOptions(); // load saved options

  // other initialization code here
  
  
ssInit:=1// notify that we have already initialized
end

EDIT: For non-app programs, you can replace AFiles with HVars (for creating Home variables).


RE: Saving data that you do not want wiped - cyrille de brébisson - 02-06-2017 06:25 AM

Hello,

Of course, you could also use App Variables (AVars) for this, then the save/load would be automatic...

Cyrille