Hello
I have been experimenting with this problem of returning the length of time elapsed between one button (H) clicked for going to sleep and another (9) clicked for standing up - and returning the result to a field "Trap5". But the result is only the actual time when button 9 is clicked.
Can somebody detect which errors I commit ?
if item 1 of parameterlist is "H" and item 2 of parameterlist is "Krop" then
put trap into chmode
put the seconds into tobed
put tab & item 1 of parameterlist & tab into trapbox
end if
if item 1 of parameterlist is "9" and item 2 of parameterlist is "Krop" then
put trap into chimed
-- set the standup of this stack to the seconds
put the seconds into standup
-- put (the seconds - the tobed of this stack) into sleeptime
subtract tobed from standup
-- subtract 3600 from sleeptime
put the value of standup into sleeptime
convert sleeptime to short time
if the number of chars of sleeptime = 8 then
put empty into char 6 to 8 of sleeptime
end if
put "Total sleep:" && sleeptime into field "Trap5"
put tab & item 1 of parameterlist & tab into trapbox
set the tobed of this stack to empty
end if
Hopefully
Kresten www.phenomenalog.dk
subtract seconds from seconds
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Re: subtract seconds from seconds
Hi.
I am not getting what you really need, I guess, because if I place two buttons on a card, and in the first one:
and in the second:
I get how many seconds between clicks. I would use a single button and toggle its label. But that is just for show.
Craig Newman
I am not getting what you really need, I guess, because if I place two buttons on a card, and in the first one:
Code: Select all
on mouseup
set the bedTime of this stack to the seconds
end mouseup
Code: Select all
on mouseUp
answer the seconds - the bedTime of this stack
end mouseUp
Craig Newman
Re: subtract seconds from seconds
Thanks,but....the result of the subtraction has to be transformed to an hour/minutes format, and shall arrive in a specified field
I tried
.....but only get "Total sleep:and the actual time" into the field.
Your solution is more or less identical with the original (dysfunctional), except we had the subtraction in a parenthesis. As I explore subtraction in the LC library I found no reference to the "-" character (the one on the key with the underline character). (I always wondered why genuine minus character is missing, when a "+" exists.
I tried
Code: Select all
if item 1 of parameterlist is "H" and item 2 of parameterlist is "Krop" then
put trap into chmode
set the tobed of this stack to the seconds
put tab & item 1 of parameterlist & tab into trapbox
end if
if item 1 of parameterlist is "9" and item 2 of parameterlist is "Krop" then
put trap into chmode
put the seconds - the tobed of this stack into sleeptime
convert sleeptime to short time
if the number of chars of sleeptime = 8 then
put empty into char 6 to 8 of sleeptime
end if
put "Total sleep:" && sleeptime into field "Trap5"
put tab & item 1 of parameterlist & tab into trapbox
set the tobed of this stack to empty
end if
Your solution is more or less identical with the original (dysfunctional), except we had the subtraction in a parenthesis. As I explore subtraction in the LC library I found no reference to the "-" character (the one on the key with the underline character). (I always wondered why genuine minus character is missing, when a "+" exists.
Re: subtract seconds from seconds
A minus character certainly exists, It is an operator. Check the dictionary.
Remember that LC is a typeless language, A dash can be either text or an operator, depending entirely on context, where it is the task of the parser to figure it out.
To change the value expressed in seconds to hours/minutes/seconds simply requires something like: (pseudo)
Notice the minus sign in the last line.
Craig
Remember that LC is a typeless language, A dash can be either text or an operator, depending entirely on context, where it is the task of the parser to figure it out.
To change the value expressed in seconds to hours/minutes/seconds simply requires something like: (pseudo)
Code: Select all
get the secondsDifference
put it div 3600 into numHours
subtract numHours * 3600 from it
put it div 60 into numMinutes
put it - numMinutes * 60 into numSeconds

Craig