Page 2 of 2

Re: How to turn fld green, red, yellow depending on when due

Posted: Tue Sep 16, 2014 12:43 am
by shawnblc
Is there some operator or something I can use to turn my field yellow for "between"?

Code: Select all

if tDueDate - tDate is between 86400 and 864000 then
set the backgroundColor of fld "fld1" to yellow 

Re: How to turn fld green, red, yellow depending on when due

Posted: Tue Sep 16, 2014 12:51 am
by Simon
Hi Shawn,
Late last night I saw that was the problem and didn't get a chance to write it down.
Let me do a picture

Code: Select all

red
---------------
2
yellow
4
----------------
green
so red is < 2
green > 4
yellow is >= 2 and yellow is <=4
in liveCode
if x >=2 and x <=4 then
set the backgroundcolor of fld "myfld" to yellow
...

Does that help?

Simon

Re: How to turn fld green, red, yellow depending on when due

Posted: Tue Sep 16, 2014 12:57 am
by shawnblc
Ah, thanks Simon. I think that'll get me on the right track. Not sure why I didn't continue on that path when I edited my original code. Thanks for the clarification. I'll post again tomorrow with my update. I'm pretty sure with that I can get this working.

* by the way, this is not application or anything yet, just creating a kitchen sink type stack with a bunch of various code while learning still. :)

Re: How to turn fld green, red, yellow depending on when due

Posted: Tue Sep 16, 2014 1:19 am
by shawnblc

Code: Select all

   put tDueDate - tDate into tTime
   if tTime > 86400 and < 604800 then
      set the backgroundColor of fld "fldDueDate" to yellow
   end if
getting this error. Code looks good, but I'm a newbie :)

Code: Select all

button "Button": compilation error at line 17 (Expression: double binary operator) near "<", char 21
EDIT: the code should have been:

Code: Select all


[code]
   put tDueDate - tDate into tTime
   if tTime > 86400 and tTime < 604800 then
      set the backgroundColor of fld "fldDueDate" to yellow
   end if
[/code]

Re: How to turn fld green, red, yellow depending on when due

Posted: Tue Sep 16, 2014 1:30 am
by Simon
Check my example...
You have to write the name both times :)

Simon

Re: How to turn fld green, red, yellow depending on when due

Posted: Tue Sep 16, 2014 1:49 am
by shawnblc
Looks like I got it now Simon, silly error on my part. Thanks.

I'll mess around with dates to make sure that it's working as I was thinking now. lol

Thanks. Fun stuff!

Code: Select all

put the system date into tDate1
   convert tDate1 to seconds
   put tDate1 into tDate
   
   put fld "fldDueDate" into tDueDate1
   convert tDueDate1 to seconds
   put tDueDate1 into tDueDate
   
   put tDueDate - tDate into tTime
   if tTime < 604800 then
      set the backgroundColor of fld "fldDueDate" to red
   end if
   
   if tTime >= 86400 and tTime <= 604800 then
      set the backgroundColor of fld "fldDueDate" to yellow
   end if
   
   put tDueDate - tDate into tTime
   if tTime > 604800 then
      set the backgroundColor of fld "fldDueDate" to green
   end if

Re: How to turn fld green, red, yellow depending on when due

Posted: Wed Sep 17, 2014 12:46 am
by shawnblc
jacque wrote:...... I was able to write the entire handler in 17 lines...............
Guess I didn't do to bad then. I'm sure it took me about 10000 times longer to do it than you though, but that's ok. :) We all started somewhere.

Re: How to turn fld green, red, yellow depending on when due

Posted: Wed Sep 17, 2014 7:14 pm
by jacque
Great! Just for comparison, here's what I put together. I was able to reduce it to 14 lines:

Code: Select all

on mouseUp
  put the seconds into tTodaySec
  put tTodaySec + (86400 * 8) into t8Day
  put tTodaySec + 86400 into t1Day
  put fld "fld1" into tDate
  convert tDate to seconds
  if tDate > t8Day then //if the date hasn't arrived yet stay green
    set the backgroundColor of fld "fld1" to green
  else if tDate <= t1Day then  //if date is date or expired turn red
    set the backgroundColor of fld "fld1" to red
  else  //if date is within 7 days of coming due turn yellow
    set the backgroundColor of fld "fld1" to yellow
  end if
end mouseUp
When you use "else if" instead of individual "if" statements, LC will execute the first matching condition and ignore all the rest. That's why this handler doesn't need to compare whether the 7-day seconds falls within a range, because if it is more than 7 days the first "if" condition will run and then the handler will skip to the end and exit. That's also why the second condition checks for an overdue, since that will eliminate the situation where the date is today's date or earlier. If it doesn't meet either of those conditions (the "else" line) then the date must fall between today and 8 days from now.

Re: How to turn fld green, red, yellow depending on when due

Posted: Fri Sep 19, 2014 1:53 am
by shawnblc
Excellent. Thank you for jumping back in the conversation.
jacque wrote:Great! Just for comparison, here's what I put together. I was able to reduce it to 14 lines:

Code: Select all

on mouseUp
  put the seconds into tTodaySec
  put tTodaySec + (86400 * 8) into t8Day
  put tTodaySec + 86400 into t1Day
  put fld "fld1" into tDate
  convert tDate to seconds
  if tDate > t8Day then //if the date hasn't arrived yet stay green
    set the backgroundColor of fld "fld1" to green
  else if tDate <= t1Day then  //if date is date or expired turn red
    set the backgroundColor of fld "fld1" to red
  else  //if date is within 7 days of coming due turn yellow
    set the backgroundColor of fld "fld1" to yellow
  end if
end mouseUp
When you use "else if" instead of individual "if" statements, LC will execute the first matching condition and ignore all the rest. That's why this handler doesn't need to compare whether the 7-day seconds falls within a range, because if it is more than 7 days the first "if" condition will run and then the handler will skip to the end and exit. That's also why the second condition checks for an overdue, since that will eliminate the situation where the date is today's date or earlier. If it doesn't meet either of those conditions (the "else" line) then the date must fall between today and 8 days from now.