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

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

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

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

Post by shawnblc » Tue Sep 16, 2014 12:43 am

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 

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

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

Post by Simon » Tue Sep 16, 2014 12:51 am

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
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

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

Post by shawnblc » Tue Sep 16, 2014 12:57 am

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. :)

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

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

Post by shawnblc » Tue Sep 16, 2014 1:19 am

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]
Last edited by shawnblc on Tue Sep 16, 2014 11:24 am, edited 1 time in total.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

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

Post by Simon » Tue Sep 16, 2014 1:30 am

Check my example...
You have to write the name both times :)

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

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

Post by shawnblc » Tue Sep 16, 2014 1:49 am

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

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

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

Post by shawnblc » Wed Sep 17, 2014 12:46 am

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.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7393
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

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

Post by jacque » Wed Sep 17, 2014 7:14 pm

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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

shawnblc
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 342
Joined: Fri Jun 01, 2012 11:11 pm

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

Post by shawnblc » Fri Sep 19, 2014 1:53 am

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.

Post Reply