Page 1 of 1
Simple Calculations
Posted: Mon Feb 28, 2011 8:08 am
by maverickalex
if i have two fields with two different values and want to subtract one from the other, how do i do it.
using this i get the answer but not displayed in the right field.
Code: Select all
subtract the value of field "endfuel" from field "startfuel"
put the result into field "fuelused"
also i am subtracting two fields containing seconds and would like to divide the result by 60 to get hours/mins is it as simple as this?
Cheers
Alex
Re: Simple Calculations
Posted: Mon Feb 28, 2011 9:59 am
by BvG
when you use subtract, then LC subtracts the first number from the last number, so the last number will be replaced by the result of the calculation. Same goes for divide, multiply, add, etc.
For example:
Code: Select all
put 5 into oneNumber
put 2 into otherNumber
subtract otherNumber from oneNumber
--now oneNumber = 3 and otherNumber = 2
you can instead use the calculation operators:
Code: Select all
put field 1 - field 2 / 60 into field 3
Re: Simple Calculations
Posted: Mon Feb 28, 2011 1:24 pm
by maverickalex
Thanks, that worked a treat, just need to figure out how to retrieve the info whilst the .txt file is being accessed by the simulator.
Re: Simple Calculations
Posted: Tue Mar 01, 2011 11:19 am
by maverickalex
I'm trying this script to convert a field which contains only seconds into hours:minutes and would like to then not display the seconds in the field "totaltime"
Code: Select all
--calculate time online
put field "timeonline" into ttimeonline
put the trunc of (ttimeonline) into tseconds
put the trunc of (tseconds /60/60) into thours
if thours < 1 then
put the trunc of thours into tminutes
end if
if tminutes < 1 then
put the trunc of thours & ":" & tminutes into field "totaltime"
end if
I know its fairly close but not quite there. i'm displaying 0:0 in my totaltime field when my timeonline field shows 600. the correct value obviously would be 0:10
Can someone point me to the errors of my ways
Re: Simple Calculations
Posted: Tue Mar 01, 2011 2:46 pm
by bn
Hi maverickAlex,
this is one way of doing it:
Code: Select all
on mouseUp
--calculate time online
-- this gives you the format for display e.g. "00:36:05"
set the numberformat to "00"
put field "timeonline" into tTimeonline
put tTimeOnline div (60*60) into tHours
subtract tHours * (60*60) from tTimeOnline
put tTimeOnline div 60 into tMinutes
subtract tMinutes * 60 from tTimeOnline
put tTimeOnline into tSeconds
-- leave out the seconds if you dont want them
put tHours & ":" & tMinutes & ":" & tSeconds into field "totaltime"
end mouseUp
kind regards
Bernd
Re: Simple Calculations
Posted: Tue Mar 01, 2011 3:00 pm
by Dixie
Hi...
This is another way
Code: Select all
on mouseUp
-- assuming the seconds count is in fld 1
put timeOnLine(fld 1)
end mouseUp
function timeOnLine timeCalc
put trunc ((timeCalc/60)/60) into theHours
put ((timeCalc/60) mod 60) into theMinutes
set itemDel to "."
put item 1 of theMinutes into theMinutes
if theMinutes < 10 then put 0 & theMinutes into theMinutes
put theHours & "." & theMinutes into totalTime
return totalTime
end timeOnLine
be well
Dixie
Re: Simple Calculations
Posted: Wed Mar 02, 2011 8:00 am
by maverickalex
Thanks to you both, they both work great,
Alex