HP Forums
Variables in a Program(A,B) - 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: Variables in a Program(A,B) (/thread-16945.html)



Variables in a Program(A,B) - matalog - 05-15-2021 08:35 PM

I have this program:

Code:
EXPORT FT2M(A,B)
BEGIN
 INPUT(A,"FT","FT",0,0,0);
 INPUT(B,"IN","IN",0,0,0);
 C:=A/3.28084;
 D:=B/39.3701;
 E:=C+D;
 //STRING (A);
 //STRING (B);
 RETURN E;
END;

What purpose do the variables in the name FT2M(A,B) serve?

They do not seem to do anything apart from require the program to be called with:

FT2M(A,B) or FT2M(2,4) e.g. Instead of just FT2M, which can be the case if I simply call the program FT2M().

Even when I enter numbers there, they have no reflection on the outcome of the program.


RE: Variables in a Program(A,B) - matalog - 05-15-2021 09:04 PM

Okay, I get it now. Those variables will enter the program, but will remain as they were initially defined by the calling of the program in the program name, although A and B will be updated and used as required by the program.

I was redefining them within the program, and although it was not outputting them in the program name, they were being used as re-defined in the program. Now that I have removed the input lines, I understand the way it works.


RE: Variables in a Program(A,B) - C.Ret - 05-16-2021 05:33 AM

Please also note that in your program, A et B are the only local variables, all the other affectations are modifying the contents of the global variables C, D and E. You have to use keyword LOCAL to design temporary variable only existing in the program environment.

Independently, concerning variables you have to daily use in different units, I greatly recommend you using the UNITS menu facilities of the HP Prime. The units of each value will be indicate in the stack avoiding a lot of mistake or worries !

To save variable with units, we have to use a different name than the reserve global variable names (the values with units can't be store in REAL or COMPLEX global variable slots). With the actual version of the software, it is easy to create user variable of versatile name, just touch (OK) when prompt for creating a new custom user variable name.


Here is a short example of what can be done with custom user variable a and b of respective value 2_ft and 4_inch :

[attachment=9475]

As you can see, any result is indicated with the corresponding unit.