Loops in Prime



#2

hello,

As a newbie here a couple of questions. I am developing a program to create corrected altitudes for barometric altimeters when the out side air temperature is less then 0'C.

EXPORT Corr_Temp(a_tmp, a_alt, f_alt)

BEGIN

HFormat:=1;
HDigits:=0;
HAngle:=1;

T:=a_tmp+.00198*a_alt;
C:=f_alt*(15-T)/(273+T-.5*.00198*(f_alt-a_alt));
F:=f_alt+C;
F:=10*ROUND(F/10);

MSGBOX("Corr Fix Alt = " +F);

END;

above is the code, rather simple and without a loop. You will notice the variables:

a_tmp
a_alt
f_alt

As you can see the program prompts for 3 variables. At the moment the program will only solve for a single f_alt at a time. What I would like to do is actually prompt for a total of five variables, the last three listed below will replace the f_alt single variable:

FAF
MDA
MAP

I can easily prompt for these variables by adding them to the Export section as follows:

EXPORT Corr_Temp(a_tmp,a_alt,FAF,MDA,MAP)

I would now like the routine to loop three times calling the old FAF and displaying the new FAF then calling the old MDA and then displaying the new MDA and finally calling the old MAP and then displaying the new MDA.

The output to be formatted like after the three loops are done:

Corrected FAF: xxxx
Corrected MDA: yyyy
Corrected MAP: zzzz

I know I need a 'for' loop command and have an idea for a local variable in the 'for' loop and a local variable for the new FAF,MDA,MAP.

So I would call FAF and store it in a local variable 'f' then run the routine, display the new FAF as above then at the end store the MDA in f and rerun the routine, displaying the new MDA then call and store MAP in f and run again.

Hope I have explained the problem. Any takers, as I am going to run this through my brain and try to solve it. Maybe someone can beat me to it!

oh yes, the other question. I have read that you can create your own apps based on your programs, and as Joe just posted, move apps to the front of the list. Can you change the icon for the app? I know how to create the app but not how to change the icon.

Cheers, Geoff


Edited: 2 Oct 2013, 11:37 a.m. after one or more responses were posted


#3

> Can you change the icon for the app?

For now, you have to use one of the already-existing icons. Whether a future firmware version will allow custom icons, or whether external development tools will be created for such things, remains to be seen. I'm keeping my fingers crossed!


#4

Joe, You are still up!!

That's what I read but I was hoping my manual was an older version!

Cheers

#5

What you want to do can be easily accomplished with an array. Since I do not have a Prime at hand, here's a solution in Visual Basic:

Function Corr_Temp(a_tmp, a_alt, FAF, MDA, MAP)
 
Dim ff(3), Message(3)
 
ff(1) = FAF
ff(2) = MDA
ff(3) = MAP
 
Message(1) = "Corrected FAF = "
Message(2) = "Corrected MDA = "
Message(3) = "Corrected MAP = "
 
For i = 1 To 3
f_alt = ff(i)
T = a_tmp + 0.00198 * a_alt
C = f_alt * (15 - T) / (273 + T - 0.5 * 0.00198 * (f_alt - a_alt))
f = f_alt + C
f = 10 * Round(f / 10, 0)
MsgBox Message(i) + Str$(f)
Next
 
End Function

Another (IMHO more elegant) option is a separate calculation function that is called three times:

Function Corr_Temp(a_tmp, a_alt, FAF, MDA, MAP)
x = Calculation(a_tmp, a_alt, FAF)
MsgBox "Corrected FAF = " + x
x = Calculation(a_tmp, a_alt, MDA)
MsgBox "Corrected MDA = " + x
x = Calculation(a_tmp, a_alt, MAP)
MsgBox "Corrected MAP " + x
End Function
 
Function Calculation(a_tmp, a_alt, f_alt)
T = a_tmp + 0.00198 * a_alt
C = f_alt * (15 - T) / (273 + T - 0.5 * 0.00198 * (f_alt - a_alt))
F = f_alt + C
F = 10 * Round(F / 10, 0)
Calculation = Str$(F)
End Function
Quote:
Hope I have explained the problem. Any takers, as I am going to run this through my brain and try to solve it. Maybe someone can beat me to it!

I hope so. ;-)

Dieter


#6

Thanks Dieter!

That's looks similar to tsolution on my 71b and completely forgot to check it!

I will convert the first one into equivalent Prime code as soon as I read up on matrices.

Cheers, Geoff

Edited: 2 Oct 2013, 10:47 a.m.


Possibly Related Threads...
Thread Author Replies Views Last Post
  39gii Tutorial: FOR loops is posted Eddie W. Shore 0 343 03-16-2013, 12:13 PM
Last Post: Eddie W. Shore
  Using loops and SOLVE together Matt Agajanian 5 599 03-25-2012, 09:02 PM
Last Post: bill platt
  Loops of Addition benchmark for the 41CL Monte Dalrymple 8 732 08-19-2010, 09:48 PM
Last Post: Wlodek Mier-Jedrzejowicz
  Loops of addition Palmer O. Hanson, Jr. 7 639 06-21-2010, 05:26 AM
Last Post: Don Shepherd
  Loops on 48GX V Green 3 440 04-25-2005, 05:53 AM
Last Post: Raymond Del Tondo
  loops V Green 3 411 02-12-2005, 03:21 AM
Last Post: Vieira, Luiz C. (Brazil)
  17BII and 19BII indefinite loops ? Vincent Weber 0 237 09-10-2004, 03:52 AM
Last Post: Vincent Weber

Forum Jump: