How can I maintain a variables value when editing a Program or App
|
12-17-2014, 06:52 PM
Post: #1
|
|||
|
|||
How can I maintain a variables value when editing a Program or App
I have about 10 variables I need to save that are defined in an App. If I open up that App for editing, any EXPORTED variables are reset, LOCAL variables disappear when the App ends, and the GLOBAL App variables (variables that are only seen internally in the App) are reset. Searching the manual, I could store to a MATRIX, but that adds another file outside the App. Another thread has talked about using NOTES to programmatically store and retrieve variable values, but I am unclear as to if that can be done with the App note, or how to do it. I've searched the online manual and the calculator help file, tried some of the examples, and it's still unclear to me. If any one could provide some more detail, or even if it is possible to programmatically store and retrieve multiple variables from the App note file, it would be appreciated.
Thanks in advance. RCF |
|||
12-17-2014, 07:33 PM
Post: #2
|
|||
|
|||
RE: How can I maintain a variables value when editing a Program or App
One way I thought about doing this the following:
1. Use a user-created variable. If the variable doesn't exist, prompt the user to create it by typing in something like: SaveData:=0; in the Home view. The app should never proceed if this variable doesn't exist. So how do we test if it exists without compile errors? Via indirection. Code: LOCAL MyData; The AbortApp() routine should display a message telling the user how to create the variable SaveData. It should also contain the KILL command to completely exit the program/app. If there is no error, then all your data is imported into MyData and you can proceed as usual. If MyData is a list of stuff, then MyData(1) will get the 1st element, MyData(2) will get the 2nd element, etc. 2. To save your data, encapsulate everything into a single list and store it into MyData. Now, export using: Code:
Thus you use MyData to access the data, and the EXPR() command to do your importing and exporting. Anytime you change your code, SaveData is unchanged. And compiling doesn't produce errors since there is no direct reference to SaveData. Graph 3D | QPI | SolveSys |
|||
12-17-2014, 07:37 PM
(This post was last modified: 12-17-2014 07:55 PM by Snorre.)
Post: #3
|
|||
|
|||
RE: How can I maintain a variables value when editing a Program or App
Hello,
a dirty solution may look like: Code: x:=1,y:=2,z:=3; |
|||
12-17-2014, 08:16 PM
Post: #4
|
|||
|
|||
RE: How can I maintain a variables value when editing a Program or App
The tradeoff in using self-modifying code is that if your data is large, the use of self-modifying code creates unnecessary bloat in program size. Not to mention the extra scrolling that needs to be done when editing the program. However, if you only have 10 values to save then this is probably not much of an issue.
Graph 3D | QPI | SolveSys |
|||
12-18-2014, 07:13 AM
Post: #5
|
|||
|
|||
RE: How can I maintain a variables value when editing a Program or App
Hello,
Nice creatives solutions to the problem! I am having a hard time finding other ones, so you guys are doing good... Have you thought about using a note? You could, upon program completion, create a note that contains a sequence of assignments "var1:=value; ....." and create either a function called at program start, or called by hand when you just recompiled the program (actually, even better, upon variable initialization) that would reload everything... something like the function bellow would save the variables (I think, I have not tested it). call/use it when exiting your program... local MyRememberedVarList= { 'var1', 'var2', 'var3' ... } Notes("MyProgramNave_SavedVars"):= SIGMALIST(EXECON("""&1:=+&2;\n""", MyRememberedVarList, eval(MyRememberedVarList)); Now, for the reloading, as the LAST global variable declared in your program (non exported), do: RELOAD:= IFTE(POS(Notes, "MyProgramNave_SavedVars"), 0, EXPR(Notes("MyProgramNave_SavedVars"))); This will cause, upon program compilation, the IFTE command to be executed. And that command should reload all program variables automaticaly... unless I messed up somewhere... convoluted hey! Cyrille |
|||
12-19-2014, 09:03 AM
Post: #6
|
|||
|
|||
RE: How can I maintain a variables value when editing a Program or App
(12-18-2014 07:13 AM)cyrille de brébisson Wrote: Now, for the reloading, as the LAST global variable declared in your program (non exported), do:Very Nice ! It works with a swap of the IFTE True and False Clauses: RELOAD:= IFTE(POS(Notes, "MyProgramNave_SavedVars"), EXPR(Notes("MyProgramNave_SavedVars")), 0); |
|||
12-21-2014, 11:35 PM
(This post was last modified: 12-21-2014 11:41 PM by Bob Frazee.)
Post: #7
|
|||
|
|||
RE: How can I maintain a variables value when editing a Program or App
Well, I am still unable to get the instructions to work. This is an APP. I need to preserve the numerical values of DegF and Mph during editing of the APP code and am attempting to store the variables in the APP's note file (called info, I believe). The code below works, so can someone modify the code with the above instructions that Didier and Cyrille has provided, so I don't lose the numerical values of DegF and Mph when I edit the APP. Also, I was unable to find the Instruction SIGMALIST in the online manual or calculator help. I am using Rev 6975 firmware update. Here's the code;
Code:
RCF |
|||
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:
Code: //Variables... (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; Code: F1:=DegF; Code: //Variables... |
|||
01-24-2015, 01:41 AM
Post: #9
|
|||
|
|||
RE: How can I maintain a variables value when editing a Program or App
Thanks very much for all your suggestions. I used the "edit" suggestion by Didier, because I wanted to keep the variables inside the app. I had not even thought of doing something like that. Thanks again.
rcf |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)