Should'nt global variables be available to subroutines?
|
03-15-2015, 07:16 PM
Post: #1
|
|||
|
|||
Should'nt global variables be available to subroutines?
I got my HP Prime two week ago, so I am kinda new at this. I started working on a program with a subroutine, but the subroutine would not work unless all variables used in the subroutine were pass to the subroutine when I called the subroutine. Should not the global variables (in this case Q, N, D, and S) be accessible for use by the subroutine? Am I doing something wrong with my code? I though global variables and system variables (A through Z) were supposed to be accessible to all programs.
My other question is do I need to declare system variables A through Z in any program that uses those variables? I find the concept of system variables, local variables and export command somewhat confusing. Thanks, Gene My program thus far:[/code][/php] Sub1(); // Main program local X1, X2, FX1, FX2; EXPORT Pipe(Q,N,D,S) BEGIN input({Q,N,D,S}, "Pipe Flow", {"Q cfs = ", "n value = ", "Dia ft = ", "Slope ft/ft = "}); // Initial X values where X = y/D X1:=0.5; X2:=0.8; // Determine f(x1) FX1:=Sub1(X1,Q,N,D,S); print (FX1) END; // Subroutine to calc f(x) Sub1(X,Q,N,D,S) //Why should Q,N,D,S need to be included? BEGIN local theta, A, R; theta:= acos(1 - 2*X); A:= (D^2 / 4) * (theta - 0.5*sin(2*theta)); R:= (D/4) * (1 − sin(2 * theta) / (2*theta)); return (1.486/N)*A*R^(2/3)*S^(1/2) - Q; END; |
|||
03-15-2015, 09:41 PM
Post: #2
|
|||
|
|||
RE: Should'nt global variables be available to subroutines?
Found my answer. For good articles on programming the HP Prime, see the Article Forum on the main page of this website. They are much more detail than the HP manual. Take a look at:
HP Prime Programming: An Introduction by Han HP Prime Programming: Variable types and their properties by Han |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)