Post Reply 
Where can I place a code in app’s program, which will be executed just once?
09-14-2016, 07:52 AM
Post: #1
Where can I place a code in app’s program, which will be executed just once?
Hello All,
I am very new user of HP Prime. And my questions regarding a basic program structure for app are maybe trivial… Not for me:-) My first standalone program (not for app) works fine, so I have decided to rewrite into function based app.

The code handling user's selections must be only placed between BEGIN and END under some created VIEW. See the example below. Sub-routines are placed out of VIEW's declaration and called out from VIEW's section (also, function of VIEW can be called out as sub). All VIEWs are easily accessible by the user (VIEW key and its selection). Where can I place a code in app’s program, which will be executed just once? For example, loading of init. constants after launching of app. Need some info "App just launched"... At this moment, my constants are always refreshed (sub INIT_DATA()) when user selects “Info”. But it is not necessary. Easy to do in standalone program…

My second question. How can I disable selected VIEW’s option? To be temporarily not accessible to the user.
Thank you for reply in advance.
Best regards,
Pavel

VIEW "Info",START()
BEGIN
RECT_P();
INIT_DATA();
.
.
END;

INIT_DATA();
BEGIN
.
.
END;
Find all posts by this user
Quote this message in a reply
09-14-2016, 03:07 PM
Post: #2
RE: Where can I place a code in app’s program, which will be executed just once?
To have the initialized on app load, you'll want to put code in the application "Start".

VIEW "Start",START()

Note that this will be executed on every application load - if the user starts the app programmatically, switches to another then back, etc. If you need to avoid it for certain circumstances, maybe combining with part 2 below would be helpful.

For the second, I'd probably recommend an app program global variable that you can set and then check in your VIEW code. This would be a variable in your app scope, but not exported to help avoid it being messed with. It would be set when compiling/installing the app for the first time.

<...program file start...>

DiasableView1:=0;

VIEW "Plot",START()
BEGIN
if(DisableView1) then ...
else ... end
END;

That might work to accomplish what you are thinking.

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
09-15-2016, 07:31 AM
Post: #3
RE: Where can I place a code in app’s program, which will be executed just once?
Hello,

The START function get executed everytime the app is Started, not everytime it is loaded.

Unfortunately, you can not easily add/remove views programmatically (well, you can if you modify the program, which can be done programmatically using the AProgram variable, but not easy to do).

As Tim pointed out, you can make the view non executing and displaying an error message, but that is about it.

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
09-16-2016, 01:14 PM
Post: #4
RE: Where can I place a code in app’s program, which will be executed just once?
Hello Tom and Cyrille,
Thank you very much for your replies. Tom's advice with global variable within app scope seems to be a good solution. Just first variable setting at compiling/installing the app is not so user friendly. I will try it.

Thanks again, have a nice weekend.
Pavel
Find all posts by this user
Quote this message in a reply
Post Reply 




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