HP Forums
Where can I place a code in app’s program, which will be executed just once? - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Where can I place a code in app’s program, which will be executed just once? (/thread-6853.html)



Where can I place a code in app’s program, which will be executed just once? - Pavel OK1DNZ - 09-14-2016 07:52 AM

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;


RE: Where can I place a code in app’s program, which will be executed just once? - Tim Wessman - 09-14-2016 03:07 PM

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.


RE: Where can I place a code in app’s program, which will be executed just once? - cyrille de brébisson - 09-15-2016 07:31 AM

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


RE: Where can I place a code in app’s program, which will be executed just once? - Pavel OK1DNZ - 09-16-2016 01:14 PM

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