Help with calculating answer from Field inputs [SOLVED]
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Help with calculating answer from Field inputs [SOLVED]
Edited Post as no reply:-
I guess as only one person downloaded the attachment that is not the way to get an answer and so here goes again.
This is my third day with LiveCode and a heck of a lot of hours working on what I thought would be a fairly simple first try in creating the first part of my App which will eventually use both Time and Distance calculations.
I do hate asking but I just can't find any simple explanation in all my searches and readings, but then I'm not the sharpest knife in the draw.
I have 2 fields asking for the user to enter the release (start) and arrival times and I require the third field to give the time taken answer, but I never get an answer displayed with my code.
I'm not sure if I have to give every code detail here or the link to my livecode file which I have uploaded. (file is now deleted)
As I build my App I will need the answer field to be called on again when I have coded the distance after finding this Post answer.
The two input fields have been entered in this format 09:12:57
The code in my answer field is:-
on mouseUp
-- system time formats
put the long system time into field "LongSysTime"
put (field Arrived - field Released) into field Answer
end mouseUp
Regards,
Ruth
I guess as only one person downloaded the attachment that is not the way to get an answer and so here goes again.
This is my third day with LiveCode and a heck of a lot of hours working on what I thought would be a fairly simple first try in creating the first part of my App which will eventually use both Time and Distance calculations.
I do hate asking but I just can't find any simple explanation in all my searches and readings, but then I'm not the sharpest knife in the draw.
I have 2 fields asking for the user to enter the release (start) and arrival times and I require the third field to give the time taken answer, but I never get an answer displayed with my code.
I'm not sure if I have to give every code detail here or the link to my livecode file which I have uploaded. (file is now deleted)
As I build my App I will need the answer field to be called on again when I have coded the distance after finding this Post answer.
The two input fields have been entered in this format 09:12:57
The code in my answer field is:-
on mouseUp
-- system time formats
put the long system time into field "LongSysTime"
put (field Arrived - field Released) into field Answer
end mouseUp
Regards,
Ruth
Last edited by morrell on Fri Dec 19, 2014 10:25 pm, edited 1 time in total.
Re: Help with calculating answer from Field inputs
Hi Ruth
Welcome in this forum
You have to convert date to seconds for working with date. Something like that
Have a look to "convert" in the LC dictionary and
dont' forget quote object names and litteral
Best regards
Jean-Marc
Welcome in this forum
Yes. You can do it after 10 postsI guess as only one person downloaded the attachment that is not the way to get an answer and so here goes again.
Code: Select all
put (field Arrived - field Released) into field Answer
Code: Select all
put fld "fStartTime" into tStartTime
put fld "fEndTime" into tEndTime
convert tStartTime to seconds
convert tEndTime to seconds
answer "tEndTime-tStartTime =" && tEndTime-tStartTime && "seconds"
dont' forget quote object names and litteral
Best regards
Jean-Marc
https://alternatic.ch
-
- Livecode Opensource Backer
- Posts: 447
- Joined: Mon Jan 23, 2012 12:46 pm
Re: Help with calculating answer from Field inputs
These stacks are a great resource:
http://www.hyperactivesw.com/revscriptc ... ences.html
The Time and Date stack should help.
--Sefro
http://www.hyperactivesw.com/revscriptc ... ences.html
The Time and Date stack should help.
--Sefro
Re: Help with calculating answer from Field inputs
Hi.
The wonder, and danger, of LC is that it seems that you can just start writing code. Your first try was logically sound, but was not syntactically sound. As Jean-Marc said, you have to convert the time and date info into a form that LC understands, the "seconds" being one option, and a good one. Then the subtraction makes sense to the engine, and you are on your way. This will trip you up again. That is normal.
Keep playing, and keep writing to this forum. Endless help available here.
Craig Newman
The wonder, and danger, of LC is that it seems that you can just start writing code. Your first try was logically sound, but was not syntactically sound. As Jean-Marc said, you have to convert the time and date info into a form that LC understands, the "seconds" being one option, and a good one. Then the subtraction makes sense to the engine, and you are on your way. This will trip you up again. That is normal.
Keep playing, and keep writing to this forum. Endless help available here.
Craig Newman
Re: Help with calculating answer from Field inputs
Well it is now day four into Live Code and my grandson who is in his late 20s said "Nana, your never going to do an App as there is so much involved", but I'm determined to prove him and others wrong.
Well I'm making progress (but slow) on my Time and Distance App thanks to Jean-Marc's example. However I'm stuck again after hours of searching on a "put" command which I'm not sure if I should submit a new Post question rather than ask here.
I know this "put" works if the into field is on the same Card:-
put (field zMiles) into field hMiles
But I want it to go on another Card in my Header Stack and I have failed to find an answer how to do it as all my attempts error and this is my latest error attempt:-
put (field zMiles) into group "HEADER" of card "HideCards") into field hMiles
Regards,
Ruth
Well I'm making progress (but slow) on my Time and Distance App thanks to Jean-Marc's example. However I'm stuck again after hours of searching on a "put" command which I'm not sure if I should submit a new Post question rather than ask here.
I know this "put" works if the into field is on the same Card:-
put (field zMiles) into field hMiles
But I want it to go on another Card in my Header Stack and I have failed to find an answer how to do it as all my attempts error and this is my latest error attempt:-
put (field zMiles) into group "HEADER" of card "HideCards") into field hMiles
Regards,
Ruth
Re: Help with calculating answer from Field inputs
Hi Ruth,
In this case you can do:
Best regards
Jean-Marc
I understand you have a fld "hMiles" in group "HEADER" of cd "HideCards".put (field zMiles) into group "HEADER" of card "HideCards") into field hMiles
In this case you can do:
Code: Select all
put field "zMiles" into field "hMiles" of group "HEADER" of card "HideCards"
Jean-Marc
https://alternatic.ch
Re: Help with calculating answer from Field inputs
Thank you again Jean-Marc. However, I get this error message after running the App:-
button "Button": execution error at line 2 (Chunk: can't find background), char 1
Regards,
Ruth
button "Button": execution error at line 2 (Chunk: can't find background), char 1
Regards,
Ruth
Re: Help with calculating answer from Field inputs
Hi...
Can you post the script of the object that is causing the error ?
Can you post the script of the object that is causing the error ?
Re: Help with calculating answer from Field inputs
Hi Ruth,
did you read Jean-Marcs answer? He wrote:
If yes, does it contain a field named "hMiles"?
If no, maybe you just mean to:
...
put field "zMiles" into field "hMiles" of card "HideCards"
...
?
As you see, we can only guess until you supply further and more detailed information, but I am good at that
Best
Klaus
did you read Jean-Marcs answer? He wrote:
So the question is simple: Do you have a group named "HEADER" on your card "HideCards"?I understand you have a fld "hMiles" in group "HEADER" of cd "HideCards".
If yes, does it contain a field named "hMiles"?
If no, maybe you just mean to:
...
put field "zMiles" into field "hMiles" of card "HideCards"
...
?
As you see, we can only guess until you supply further and more detailed information, but I am good at that

Best
Klaus
Re: Help with calculating answer from Field inputs
Thank you Klaus and you are "Good at guessing" as your code worked fine.
Obviously I now know I don't have a Group named Header and so once again I'm on yet another learning curve as I thought the Stack was a group.
Regards,
Ruth
Obviously I now know I don't have a Group named Header and so once again I'm on yet another learning curve as I thought the Stack was a group.
Regards,
Ruth
Re: Help with calculating answer from Field inputs
Hi Ruth,
I can recommend these great stacks for learning more about the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html
Best
Klaus

I can recommend these great stacks for learning more about the basics of Livecode:
http://www.hyperactivesw.com/revscriptc ... ences.html
Best
Klaus
Re: Help with calculating answer from Field inputs
Jean-Marc gave this example which results in an Answer screen.
However, I need the number of seconds obtained to be placed in a new Field, as I need to use that new field for calculation later and as usual I'm unable to find out how to do it.
Also, again I have failed to fathom out how that new field which will contain the seconds is then converted back into a new field of the long time format.
Regards,
Ruth
Code: Select all
put fld "fStartTime" into tStartTime
put fld "fEndTime" into tEndTime
convert tStartTime to seconds
convert tEndTime to seconds
answer "tEndTime-tStartTime =" && tEndTime-tStartTime && "seconds"
Also, again I have failed to fathom out how that new field which will contain the seconds is then converted back into a new field of the long time format.
Regards,
Ruth
Re: Help with calculating answer from Field inputs
Hi Ruth,
If I understand you correctly, you can use something like that:
I'm confused with last convert because
return 1:02:05 AM.
I expected 0:02:05 AM
Best regards
Jean-Marc
If I understand you correctly, you can use something like that:
However, I need the number of seconds obtained to be placed in a new Field
Code: Select all
put (tEndTime - tStartTime) into tSecondsPassed
Also, again I have failed to fathom out how that new field which will contain the seconds is then converted back into a new field of the long time format.
Code: Select all
convert tSecondsPassed from seconds to long time
put tSecondsPassed into fld "myNewField"
Code: Select all
convert 125 from seconds to long time
I expected 0:02:05 AM
Best regards
Jean-Marc
https://alternatic.ch
Re: Help with calculating answer from Field inputs
Time elapsed is different from a time/date conversion. The time and date conversions are based on your time zone, daylight savings time, the number of days in a month, etc. Elapsed time is simply a number of time units without any date information.return 1:02:05 AM.
I expected 0:02:05 AM
To convert elapsed time to minutes and seconds, the script must calculate each unit separately and then combine the results into a string:
Code: Select all
put fld "myNewField" into tElapsed -- use the correct field name here
set the numberformat to "00"
put tElapsed div 60 into tMins
put tElapsed mod 60 into tSecs
put tMins & colon & tSecs into fld "elapsedTime
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Help with calculating answer from Field inputs
Thank You jacque.
So far the time code I'm up to is below and once this is working as I want it, then distances will be added afterwards where I need the tSecondsPassed field for use in the distance part:-
You need to know the ReleasedM and ArrivedM fields are entered in this 24 hour time format 00:02:09 (no Date or AM/PM) and the myNewField is also only to display the 24 hour format 00:02:09 with no Date or AM/PM
With the help from Klaus and Jean-Marc I'm nearly there on the time aspect of my App project, which just leaves myNewField to give the correct answer for the time obtained from tSecondsPassed and to display in 24 hour time with no AM/PM. Example 00:57:07 even if there are no hours.
The App user only sees on screen their inputs and the b]myNewField[/b] as that field is an answer to the time difference which they want to know.
Regards,
Ruth
So far the time code I'm up to is below and once this is working as I want it, then distances will be added afterwards where I need the tSecondsPassed field for use in the distance part:-
Code: Select all
on mouseUp
put field "ReleasedM" into tReleasedM
put field "ArrivedM" into tArrivedM
put tReleasedM into field "ReleasedMCopy"
put tArrivedM into field "ArrivedMCopy"
convert tReleasedM to seconds
convert tArrivedM to seconds
put (tArrivedM - tReleasedM) into tSecondsPassed
put tSecondsPassed into field "tSecondsPassed"
convert tSecondsPassed from seconds to time
put tSecondsPassed into field "myNewField"
end mouseUp
With the help from Klaus and Jean-Marc I'm nearly there on the time aspect of my App project, which just leaves myNewField to give the correct answer for the time obtained from tSecondsPassed and to display in 24 hour time with no AM/PM. Example 00:57:07 even if there are no hours.
The App user only sees on screen their inputs and the b]myNewField[/b] as that field is an answer to the time difference which they want to know.
Regards,
Ruth