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!
I'm trying to get a fld turn colors depending on when something is due or not due. Example: turn yellow when something is coming due, red when it is due or past due, and green when it's good. Can someone help me out with the below code. Can't seem to get it right.
put 8 into t8Day -- the num of days
put the seconds into tTodaySec
put 86400 * t8Day into tTimePassed
put tTodaySec + tTimePassed into tDaysec
convert tDaysec to short date
--answer "In " && t8Day && "day we will be the" && tDaysec
put 7 into t7Day -- the num of days
put the seconds into tTodaySec
put 86400 * t7Day into tTimePassed
put tTodaySec + tTimePassed into tDaysec
convert tDaysec to short date
answer "In " && t7Day && "day we will be the" && tDaysec
put -7 into tM7Day -- the num of days
put the seconds into tTodaySec
put 86400 * tM7Day into tTimePassed
put tTodaySec + tTimePassed into tDaysec
convert tDaysec to short date
answer "In " && tM7Day && "day we will be the" && tDaysec
put 1 into t1Day -- the num of days
put the seconds into tTodaySec
put 86400 * t1Day into tTimePassed
put tTodaySec + tTimePassed into tDaysec
convert tDaysec to short date
--answer "In " && t1Day && "day we will be the" && tDaysec
if fld "fld1" > t8Day //if the date hasn't arrived yet stay green
then
set the backgroundColor of fld "fld1" to green
exit mouseup
end if
if fld "fld1" <= t1Day //if date is date or expired turn red
then
set the backgroundColor of fld "fld1" to red
exit mouseUp
end if
if fld "fld1" >= tM7Day //if date is within 7 days of coming due turn yellow
then
set the backgroundColor of fld "fld1" to yellow
exit mouseUp
end if
if fld "fld1" <= tM8Day
then
set the backgroundColor of fld "fld1" to red
exit mouseUp
if fld "fld1" > tM8Day
then
set the backgroundColor of fld "fld1" to green
exit mouseUp
end if
Still not working how I'd expect it to. I'll post my code again here in shortly. Just wanted to update the thread for now. Give me 30 to 60 minutes and I'll post updated code.
Besides comparing seconds rather than dates, the script also doesn't actually populate the variables t8Dat, t7Day, etc. It calculates the values but doesn't use those values, so the "if" statements won't work.
Also, if you use the if - else if - end if structure you won't need all the "exit mouseup" statements because only one line of the the "if" structure will ever execute. The same thing could also be done using a switch structure, but new users are generally more familiar with "if"s and it's okay to use that.
There is a lot of repetition in the calculation of the "day" variables, you could reduce that to 5 lines. I was able to write the entire handler in 17 lines, but I'm not sure if you want the answer or you would rather work it out yourself. Holler if you want me to post it.
Edit: I just noticed Simon told you about the variables already. He's right, and I should have read the thread more thoroughly.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
Hi Shawn,
Yes... I did leave a lot of the work incomplete but I hope you got the idea.
There is one other thing you should be watching out for and that is the "put the seconds..." that records the seconds right now and for a calendar type app it isn't good. You want midnight 00:00:00.
Make sense?
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
I'm getting close, but not as close as I'd like. As you can see I switched it up a bit. If I have a due date that's say 7 days out I'd like yellow. 8 or more days out green. On the day or past the date red.
on mouseUp
put 86400 * fld "fldAlert" into tTheAlert
convert tTheAlert to seconds
put fld "fldDue" into tDue
convert tDue to seconds
put the date into tToday
convert tToday to seconds
put tDue - tTheAlert into tDueDate
convert tDueDate to seconds
--answer tDueDate
if tToday - tTheAlert < tDueDate then
set the backgroundColor of fld "fldDue" to yellow
else
if tToday + tTheAlert >= tDueDate then
set the backgroundColor of fld "fldDue" to red
else
if tToday + tTheAlert < tDueDate then
set the backgroundColor of fld "fldDue" to green
else
if tToday = tDueDate then
set the backgroundColor of fld "fldDue" to red
end if
end if
end if
end if
end mouseUp