probably another simple answer

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
mister
Posts: 39
Joined: Thu Nov 27, 2014 9:03 pm

probably another simple answer

Post by mister » Sat Sep 10, 2016 10:57 pm

Hello,

This is basically a timer, which i didn't know Livecode had "built in" ones until well into my project. Regardless, gStart comes from the openCard script. This code is in a button called "time2". The problem is that each time "button time2" is pushed the time is subtracted from the gStart. The first time is correct, but after that the time should be subtracted from the line above it, not gStart. it's probably some simple math that i'm horrible at, but i've tried many, many different ways to fix this and can't find the answer. Any help is appreciated.

Code: Select all

repeat with x = 1 to the number of lines in fld "pick2"
      if the hilitedline of fld "pick2" is x then
         if item 2 of line x in fld "pick2" is empty then
            put the time into tTime
            put tTime into item 2 of line x of fld "pick2"
            convert tTime to seconds
            put tTime - gStart into sDiff
            add sDiff to fld "daysRun2" -- 
            put formatTime(sDiff) into item 3 of line x of fld "pick2"
            put 1 into item 4 of line x of fld "pick2"
         end if 
      end if 
   end repeat
Thanks,
Larry

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10305
Joined: Wed May 06, 2009 2:28 pm

Re: probably another simple answer

Post by dunbarx » Sun Sep 11, 2016 12:11 am

Hi.

Is gStart a global variable?

I see nothing updated each pass through the button click, I bet this is where the issue lies.

I have not built a stack with the fields you reference, nor the hilited properties you mention, so I cannot run your hander. But I would love you to create a more generic version so that I and others can play with your methodology, as opposed to a portion of your project.

The good news is that your problem, I will bet, can be solved in exactly one new line of code.

Craig Newman

mister
Posts: 39
Joined: Thu Nov 27, 2014 9:03 pm

Re: probably another simple answer

Post by mister » Fri Sep 16, 2016 1:52 pm

Craig

Thanks for the response, but i've been busy at work and still trying to figure this out on my own. Yes, gStart is a global variable. The time(converted to seconds) is placed in the variable gStart on openCard. What i've already posted works fine. it just keeps subtracting from gStart. i need it to subtract each line from itself. I hope this is generic enough.

Code: Select all

global gStart
put the time into gStart
convert gStart to seconds

on mouseUp
   set the twelveHourTime to true
   set the itemDel to tab
   put the time into sTime
   convert sTime to seconds
   put sTime - gStart into aTime
   put  the time & tab & formatTime(aTime)  & cr after fld "test"
end mouseUp
i have also tried this which gives the same answer.
#put sTime - gStart into aTime
#put ((gStart + aTime) - gStart) into bTime
#put formatTime(bTime) into ....

Code: Select all

function formatTime, pSeconds
local tHours, tMins, tSecs
put pSeconds div (60 * 60 ) into tHours
subtract tHours * (60*60) from pSeconds
put pSeconds div 60 into tMins
subtract tMins * 60 from pSeconds
set the numberformat to "#"
put tHours & ":"  & tMins into tFinal
return tFinal
end formatTime
Thanks again,
Larry

mister
Posts: 39
Joined: Thu Nov 27, 2014 9:03 pm

Re: probably another simple answer

Post by mister » Sun Sep 18, 2016 1:47 pm

Argggggggh!! I knew it should be simple. turns out it is, but the hundreds of different ways i tried to fix it, waiting for minutes to tick off. So, in case anyone wants to know the answer.

Code: Select all

global gStarts, 
local aTime

on mouseDown
   put the time into sTime
   convert sTime to seconds
   put sTime - gStarts into aTime
   put the time & tab & formatTime(aTime) & cr after fld "test"
end mouseDown

on mouseUp
   put (gStarts + aTime) into gStarts
end mouseUp

Post Reply