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.
EDIT: For non-app programs, you can replace AFiles with HVars (for creating Home variables).
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):={ ssSaveMode, ssMaxIter, ssFtol, ssdxtol, ssAutoVar, ssWarning, ssMarkLimit };
end;
ssLoadOptions()
begin
local l:={};
local n;
if pos(AFiles,ssUserFile) then
l:=AFiles(ssUserFile);
if (size(l) == 7) then
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 == 0) then ssFtol:=1e-9; end; // and greater than 0; use default if not positive
ssdxtol:=max(l(4),0); // must be non-negative
if (ssdxtol == 0) then ssdxtol:=1e-9; end; // 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).