Post Reply 
How can I maintain a variables value when editing a Program or App
12-22-2014, 09:42 AM (This post was last modified: 12-22-2014 12:54 PM by Didier Lachieze.)
Post: #8
RE: How can I maintain a variables value when editing a Program or App
Here is an updated code that should work as you want. It saves the value of DegF and Mph in a Note called “WindChillApp_SavedVars” and retrieve the saved values when the variables are reinitialized. I’ve not found a way to access the App internal note (Info) with the new programmatic command Notes(), this is why I used a separate Note.

Changes:
  • RELOAD line added after your variables list
  • Variables saving to Note added to InputPgm()
I removed the + and the \n from the code provided by Cyrille (in the EXECON string) as they were not recognized by EXPR (Syntax Error). I had also to remove the brackets from the string generated by EXECON (they were added around the variable name and the value and I don't know how to tell EXECON not to add them).

Code:
//Variables... 
DegF;Mph;
LOCAL wct,wcto,ft;
Local Counter,ChooseVar;
RELOAD:= IFTE(POS(Notes, "WindChillApp_SavedVars"), EXPR(Notes("WindChillApp_SavedVars")), 0);

WindChillIntroDisplay();
InputPgm();
FrostBiteEqn();
WindChillEqn();
OutputPgm();

EXPORT WindChillApp()
BEGIN
END;

VIEW "Start WindChill",START()
BEGIN
LOCAL K;

REPEAT
STARTVIEW(-1,1);
WindChillIntroDisplay();
REPEAT
Counter:=Counter+1;
IF Counter>5 THEN
MSGBOX("Program is Paused
Any Key to Continue");
Counter:=0;
BREAK;
END;
WAIT(1);
K:=GETKEY;
UNTIL K>−1;

Counter:=0;

IF K==42 OR K==43 THEN
InputPgm();
END;

IF K==30 THEN
WindChillEqn();
FrostBiteEqn();
STARTVIEW(-1,1);
OutputPgm();
WAIT(0);
END;

UNTIL K==4;
STARTVIEW(-4,0);
END;

WindChillIntroDisplay()
BEGIN
TEXTOUT("1: DegF= "+DegF,-15,9);
TEXTOUT("2: Mph= "+Mph,-15,7);
TEXTOUT("Enter: Calculate WindChill",-15,1);
TEXTOUT("Esc=Quit",-15,-1);
END;

InputPgm()
BEGIN
LOCAL MyRememberedVarList= { 'DegF', 'Mph' };
LOCAL MySavedVarString;
REPEAT
INPUT({DegF,Mph},"Input Values",{"DegF= : ","Mph=  : "},{"Air Temperature (-45 to 40 °F)","Wind Speed (3 to 60 Mph)"},{DegF,Mph});
UNTIL DegF>=-45. AND DegF<=40. AND Mph>=3. AND Mph<=60.; 
MySavedVarString:= ΣLIST(EXECON("""&1:=&2;""", MyRememberedVarList, eval(MyRememberedVarList)));
Notes("WindChillApp_SavedVars"):= REPLACE(REPLACE(MySavedVarString,"(",""),")","")
END;

FrostBiteEqn()
BEGIN

//Calculate frostbite time
CASE
IF DegF≤-45 AND Mph≥12 THEN 5▶ft END;
If DegF≤-45 and Mph≥0 Then 10▶ft END;
If DegF≤-40 and Mph≥14 Then 5▶ft END;
If DegF≤-40 and Mph≥0 Then 10▶ft END;
If DegF≤-35 and Mph≥17 Then 5▶ft END;
If DegF≤-35 and Mph≥7 Then 10▶ft END;
If DegF≤-35 and Mph≥0 Then 30▶ft END;
If DegF≤-30 and Mph≥21 Then 5▶ft END; 
If DegF≤-30 and Mph≥7 Then 10▶ft END;
If DegF≤-30 and Mph≥0 Then 30▶ft END;
If DegF≤-25 and Mph≥26 Then 5▶ft END;
If DegF≤-25 and Mph≥9 Then 10▶ft END;
If DegF≤-25 and Mph≥0 Then 30▶ft END;
If DegF≤-20 and Mph≥37 Then 5▶ft END;
If DegF≤-20 and Mph≥12 Then 10▶ft END;
If DegF≤-20 and Mph≥0 Then 30▶ft END;
If DegF≤-17 and Mph≥35 Then 5▶ft END;
If DegF≤-15 and Mph≥42 Then 5▶ft END;
If DegF≤-15 and Mph≥16 Then 10▶ft END;
If DegF≤-15 and Mph≥45 Then 30▶ft END;
If DegF≤-12 and Mph≥45 Then 5▶ft END;
If DegF≤-10 and Mph≥57 Then 5▶ft END;
If DegF≤-10 and Mph≥22 Then 10▶ft END;
If DegF≤-10 and Mph≥0 Then 30▶ft END;
If DegF≤-5 and Mph≥33 Then 10▶ft END;
If DegF≤-5 and Mph≥7 Then 30▶ft END;
If DegF≤-2 and Mph≥35 Then 10▶ft END;
If DegF≤0 and Mph≥54 Then 10▶ft END;
If DegF≤0 and Mph≥12 Then 30▶ft END;
If DegF≤2 and Mph≥55 Then 10▶ft END; 
If DegF≤2 and Mph≥15 Then 30▶ft END;
If DegF≤5 and Mph≥28 Then 30▶ft END;
If DegF≤7 and Mph≥30 Then 30▶ft END;
If DegF≤10 and Mph≥52 Then 30▶ft END;
If DegF≤12 and Mph≥55 Then 30▶ft END; 
" NOT LIKELY"▶ft;
END;
END;

WindChillEqn()
BEGIN
//New WindChill Equation
35.74+.6215*DegF−35.75*Mph^.16+.4275*DegF*Mph^.16▶wct;
round(wct,0)▶wct;

//Old WindChill Equation(Prior to 2001)
.0817*(3.71*Mph^.5+5.81-.25*Mph)*(DegF-91.4)+91.4▶wcto;
round(wcto,0)▶wcto;
END;

OutputPgm()
BEGIN
TEXTOUT("DegF= "+DegF,-15,9);
TEXTOUT("Mph= "+Mph,-15,7);
TEXTOUT("New WindChill= "+wct,-15,5);
TEXTOUT("Old WindChill= "+wcto,-15,3);
TEXTOUT("Frostbite,≤min "+ft,-15,1);
TEXTOUT("Enter=Back",-15,-1);
END;

(12-21-2014 11:35 PM)Bob Frazee Wrote:  Also, I was unable to find the Instruction SIGMALIST in the online manual or calculator help.
SIGMALIST stands for ΣLIST which is item 8 in Toolbox>List.

EDIT: If you want to keep your variables value inside your App, there is a simple way to do it in your case (limited number of simple variables): you can use the unused App internal variables to keep track of DegF and Mph. This is simpler but less generic than the solution above.
For example if you have created the “WindChillApp” from the “Function App”, you can store DegF in F1 and Mph in F2.

Here is an example with two lines added to START():
Code:
IFERR DegF:=F1 THEN DegF:=0 END;
IFERR Mph:=F2 THEN Mph:=0 END;
And two lines added to InputPgm():
Code:
F1:=DegF;
F2:=Mph;

Code:
//Variables... 
DegF;Mph;
LOCAL wct,wcto,ft;
Local Counter,ChooseVar;

WindChillIntroDisplay();
InputPgm();
FrostBiteEqn();
WindChillEqn();
OutputPgm();

EXPORT WindChillApp()
BEGIN
END;

VIEW "Start WindChill",START()
BEGIN
LOCAL K;
IFERR DegF:=F1 THEN DegF:=0 END;
IFERR Mph:=F2 THEN Mph:=0 END;
REPEAT
STARTVIEW(-1,1);
WindChillIntroDisplay();
REPEAT
Counter:=Counter+1;
IF Counter>5 THEN
MSGBOX("Program is Paused
Any Key to Continue");
Counter:=0;
BREAK;
END;
WAIT(1);
K:=GETKEY;
UNTIL K>−1;

Counter:=0;

IF K==42 OR K==43 THEN
InputPgm();
END;

IF K==30 THEN
WindChillEqn();
FrostBiteEqn();
STARTVIEW(-1,1);
OutputPgm();
WAIT(0);
END;

UNTIL K==4;
STARTVIEW(-4,0);
END;

WindChillIntroDisplay()
BEGIN
TEXTOUT("1: DegF= "+DegF,-15,9);
TEXTOUT("2: Mph= "+Mph,-15,7);
TEXTOUT("Enter: Calculate WindChill",-15,1);
TEXTOUT("Esc=Quit",-15,-1);
END;

InputPgm()
BEGIN
REPEAT
INPUT({DegF,Mph},"Input Values",{"DegF= : ","Mph=  : "},{"Air Temperature (-45 to 40 °F)","Wind Speed (3 to 60 Mph)"},{DegF,Mph});
UNTIL DegF>=-45. AND DegF<=40. AND Mph>=3. AND Mph<=60.; 
F1:=DegF;
F2:=Mph;
END;

FrostBiteEqn()
BEGIN

//Calculate frostbite time
CASE
IF DegF≤-45 AND Mph≥12 THEN 5▶ft END;
If DegF≤-45 and Mph≥0 Then 10▶ft END;
If DegF≤-40 and Mph≥14 Then 5▶ft END;
If DegF≤-40 and Mph≥0 Then 10▶ft END;
If DegF≤-35 and Mph≥17 Then 5▶ft END;
If DegF≤-35 and Mph≥7 Then 10▶ft END;
If DegF≤-35 and Mph≥0 Then 30▶ft END;
If DegF≤-30 and Mph≥21 Then 5▶ft END; 
If DegF≤-30 and Mph≥7 Then 10▶ft END;
If DegF≤-30 and Mph≥0 Then 30▶ft END;
If DegF≤-25 and Mph≥26 Then 5▶ft END;
If DegF≤-25 and Mph≥9 Then 10▶ft END;
If DegF≤-25 and Mph≥0 Then 30▶ft END;
If DegF≤-20 and Mph≥37 Then 5▶ft END;
If DegF≤-20 and Mph≥12 Then 10▶ft END;
If DegF≤-20 and Mph≥0 Then 30▶ft END;
If DegF≤-17 and Mph≥35 Then 5▶ft END;
If DegF≤-15 and Mph≥42 Then 5▶ft END;
If DegF≤-15 and Mph≥16 Then 10▶ft END;
If DegF≤-15 and Mph≥45 Then 30▶ft END;
If DegF≤-12 and Mph≥45 Then 5▶ft END;
If DegF≤-10 and Mph≥57 Then 5▶ft END;
If DegF≤-10 and Mph≥22 Then 10▶ft END;
If DegF≤-10 and Mph≥0 Then 30▶ft END;
If DegF≤-5 and Mph≥33 Then 10▶ft END;
If DegF≤-5 and Mph≥7 Then 30▶ft END;
If DegF≤-2 and Mph≥35 Then 10▶ft END;
If DegF≤0 and Mph≥54 Then 10▶ft END;
If DegF≤0 and Mph≥12 Then 30▶ft END;
If DegF≤2 and Mph≥55 Then 10▶ft END; 
If DegF≤2 and Mph≥15 Then 30▶ft END;
If DegF≤5 and Mph≥28 Then 30▶ft END;
If DegF≤7 and Mph≥30 Then 30▶ft END;
If DegF≤10 and Mph≥52 Then 30▶ft END;
If DegF≤12 and Mph≥55 Then 30▶ft END; 
" NOT LIKELY"▶ft;
END;
END;

WindChillEqn()
BEGIN
//New WindChill Equation
35.74+.6215*DegF−35.75*Mph^.16+.4275*DegF*Mph^.16▶wct;
round(wct,0)▶wct;

//Old WindChill Equation(Prior to 2001)
.0817*(3.71*Mph^.5+5.81-.25*Mph)*(DegF-91.4)+91.4▶wcto;
round(wcto,0)▶wcto;
END;

OutputPgm()
BEGIN
TEXTOUT("DegF= "+DegF,-15,9);
TEXTOUT("Mph= "+Mph,-15,7);
TEXTOUT("New WindChill= "+wct,-15,5);
TEXTOUT("Old WindChill= "+wcto,-15,3);
TEXTOUT("Frostbite,≤min "+ft,-15,1);
TEXTOUT("Enter=Back",-15,-1);
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: How can I maintain a variables value when editing a Program or App - Didier Lachieze - 12-22-2014 09:42 AM



User(s) browsing this thread: 1 Guest(s)