Count cells if they are a certain colour
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 78
- Joined: Fri Oct 03, 2008 10:13 am
- Location: ESSEX
Count cells if they are a certain colour
Hi, can anyone help, i would like to be able to count a number of cells if they are a certain colour.
any help is appreciated.
kind regards
wee wullie
any help is appreciated.
kind regards
wee wullie
Re: Count cells if they are a certain colour
HI,
please tell us WHAT cells you mean, thanks!
Best
Klaus
please tell us WHAT cells you mean, thanks!
Best
Klaus
Re: Count cells if they are a certain colour
I deleted the duplicate, please only ONE posting per question, thanks!
-
- Posts: 78
- Joined: Fri Oct 03, 2008 10:13 am
- Location: ESSEX
Re: Count cells if they are a certain colour
Hi Klaus, i have a table field that uses the following button code to color the cells which contain certain dates, i would like to be able to count the colored cells for each color:
kind regards
Code: Select all
on mouseUp
set the useSystemDate to true
put the internet date into tData
convert tData to seconds
put 60*60*24 into tSecondsADay
put 30 * tSecondsADay into t30DaysBefore
put 0 - t30DaysBefore into t30DaysAfter
put the number of lines of field "TheResultFld" into tSoManyLines
set the itemDelimiter to tab
put the number of items of line 1 of field "TheResultFld" into tSoManyItems
lock screen
put 1 into tCounter
repeat with i = 1 to tSoManyLines
repeat with j = 4 to 11 -- only items 4 through 8 will be considered
put item j of line i of field "TheResultFld" into tADate
if tADate is not a date then next repeat -- test if it is a date else go to next item
convert tADate to seconds
put tData - tADate into tDiff
if tDiff < 0 then
if tDiff >= t30DaysAfter and tDiff <= 0 then
set the backgroundColor of item j of line i of field "TheResultFld" to "184,204,228"
end if
if tDiff < t30DaysAfter then
set the backgroundColor of item j of line i of field "TheResultFld" to "146,208,80"
end if
else
if tDiff >=0 and tDiff < t30DaysBefore then
set the backgroundColor of item j of line i of field "TheResultFld" to "255,255,128"
end if
else
if tDiff >= t30DaysBefore then
set the backgroundColor of item j of line i of field "TheResultFld" to "218,150,148"
end if
end if
set the backgroundColor of item 4 of line i of field "TheResultFld" to "white"
set the backgroundColor of item 6 of line i of field "TheResultFld" to "white"
set the backgroundColor of item 8 of line i of field "TheResultFld" to "white"
set the backgroundColor of item 10 of line i of field "TheResultFld" to "white"
end repeat
end repeat
unlock screen
end mouseUp
Re: Count cells if they are a certain colour
Hi,
AHA!
OK, I never worked with the TABLE field, but this should be done with a repeat loop
through all lines and then through all ITEMS (set itemdel to TAB) and check and count
their (items) "backgroundcolor".
Know what I mean?
Best
Klaus
AHA!
OK, I never worked with the TABLE field, but this should be done with a repeat loop
through all lines and then through all ITEMS (set itemdel to TAB) and check and count
their (items) "backgroundcolor".
Know what I mean?
Best
Klaus
-
- Posts: 78
- Joined: Fri Oct 03, 2008 10:13 am
- Location: ESSEX
Re: Count cells if they are a certain colour
No, still cant get it to work, but thanks Klaus, i'll try something else.
Re: Count cells if they are a certain colour
Hm, if you can SET the backgroundcolor, you can also GET the backgroundcolor!wee wullie wrote:No, still cant get it to work, but thanks Klaus, i'll try something else.
What did you try so far?
-
- Posts: 78
- Joined: Fri Oct 03, 2008 10:13 am
- Location: ESSEX
Re: Count cells if they are a certain colour
Yes Klaus, i can SET and GET the bg color like this:
but i cant seem to be able to count how many times that color occurs.
kind regards
Code: Select all
set the backgroundColor of item j of line i of field "TheResultFld" to "146,208,80"
get the backgroundColor of item j of line i of field "TheResultFld"
put it into tGbg
answer tGbg
kind regards
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Count cells if they are a certain colour
Not sure but:
The new thing I learned was you can't use a "repeat for each line..." because backgroundColor wont be in that, so you must always reference the table. (I should have seen that faster).
Simon
Code: Select all
on mouseUp
set the itemDelimiter to tab
repeat with i = 1 to the number of lines in fld "TheResultFld"
repeat with j = 1 to the number of items in line i of fld "TheResultFld" -- I think you have 4-11
get the backgroundColor of item j of line i of fld "TheResultFld"
if it = "146,208,80" then
add 1 to tGbg
end if
end repeat
end repeat
answer tGbg
end mouseUp
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Posts: 78
- Joined: Fri Oct 03, 2008 10:13 am
- Location: ESSEX
Re: Count cells if they are a certain colour SOLVED
Hi Simon, that works perfectly, i use that in a handler that outputs to several fields as totals, and it totals the colored items as expected, however where there are no items to total it leaves the field blank, i tried to use
but it only puts zero into the first empty field and leaves the rest blank, i tried an answer dialog to check the variables and strangely the zeros show in the fields while the dialog box is open then they disapear when it closes.
Code: Select all
if tGbg = 0 then
put "0" into fld "Gbg1"
put "0" into fld "Ybg1"
put "0" into fld "Bbg1"
put "0" into fld "Rbg1"
end if
Re: Count cells if they are a certain colour
Hi,
if a variable is empty and not yet used, its content will be its NAME!
Avoid this by "initializing" it like this:
NOW tGgb will be 0 if no colored cells are found!
Best
Klaus
if a variable is empty and not yet used, its content will be its NAME!
Avoid this by "initializing" it like this:
Code: Select all
on mouseUp
## INIT variable HERE:
put 0 into tGgb
set the itemDelimiter to tab
repeat with i = 1 to the number of lines in fld "TheResultFld"
repeat with j = 1 to the number of items in line i of fld "TheResultFld" -- I think you have 4-11
get the backgroundColor of item j of line i of fld "TheResultFld"
if it = "146,208,80" then
add 1 to tGbg
end if
end repeat
end repeat
answer tGbg
end mouseUp
Best
Klaus
-
- Posts: 78
- Joined: Fri Oct 03, 2008 10:13 am
- Location: ESSEX
Re: Count cells if they are a certain colour
Never thought of that, nice 1 Klaus, thanks for that and THANK YOU SIMON, my handler has 16 vars to INIT and i thought there might be a problem but everything works fine, thanks guys.
Kindest Regards
Wullie
Kindest Regards
Wullie
-
- VIP Livecode Opensource Backer
- Posts: 3901
- Joined: Sat Mar 24, 2007 2:54 am
- Location: Palo Alto
Re: Count cells if they are a certain colour
Glad to help you Wullie.
Keep asking those questions
Simon
Keep asking those questions
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!