Post Reply 
Program local variables issue
02-11-2020, 06:25 AM (This post was last modified: 02-11-2020 06:28 AM by Wes Loewer.)
Post: #8
RE: Program local variables issue
(02-11-2020 04:34 AM)Gene222 Wrote:  For a good explanation of how to program with local variables, see 4.2) HP Prime Programming: Variable types and their priorities. This document is located within the HP-Prime: Documentation & Tutorials located at the top of this forum.

If I'm reading this document correctly, then its description of local variables defined outside of a function is not correct. It says:

Quote:Unlike local variables declared inside a program block, such as var7, local variables declared outside of any program block retain their values even after program execution reaches completion and up until the source is recompiled. This is the only effective difference. They are still not accessible to programs defined in a separate source file, or the user.

Here is a counterexample. Create these two program in separate source files.
Code:
LOCAL var1:=1;

EXPORT PROG1()
BEGIN
 RETURN var1;
END;
and
Code:
EXPORT PROG2()
BEGIN
 PROG1.var1:=PROG1.var1+1;
 RETURN PROG1.var1; 
END;

Run PROG1, then PROG2 and you see that var1 has changed. If you run PROG1 again, it confirms that var1 really has changed. Likewise, you can alter PROG1.var1 from the Home screen as well.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Program local variables issue - DrDarius - 02-10-2020, 02:25 AM
RE: Program local variables issue - Wes Loewer - 02-11-2020 06:25 AM



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