Post Reply 
Saving data that you do not want wiped
02-05-2017, 11:35 PM (This post was last modified: 02-06-2017 01:19 AM by Han.)
Post: #1
Saving data that you do not want wiped
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).

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
02-06-2017, 06:25 AM
Post: #2
RE: Saving data that you do not want wiped
Hello,

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

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: