Page 1 of 3
hilite text
Posted: Thu Nov 05, 2009 12:50 am
by smash
i have a table of different percentage numbers
is there a way, to press a button that will hilite the highest number % say blue, the second highest number % red, the third highest number % white and so on, all in the one table ??
i hope someone can help me
cheers
Posted: Thu Nov 05, 2009 9:05 am
by SparkOut
Hi smash!
Are the values in one column? or spread over multiple columns?
And you want the first, second and third % values to be hilited (as in gold medal, silver and bronze) right, rather than "the top x% blue" etc?
Assuming one column, then if you set theItemDelimiter to tab and "sort <tablename> by item <column number>" that should do the trick. You can preserve the contents of the table in order if you copy to a variable first and then use lineOffset to get the corresponding line number. Or use "max" to find the highest value and then seek it.
How would you need to deal with ties?
Posted: Thu Nov 05, 2009 10:09 am
by smash
hi sparkout.
the values are all in one column, (column 4)
now i have this script to sort
on mouseUp
sort lines of field "Entries" ascending text
sort lines of tText descending text
sort of field "Entries" ascending numeric
sort of tItems descending numeric
end mouseUp
but it will only sort the values in the first column instead of column4
but i thought, instead of "sorting" it would be much easier if i could just select certain colours to hilite the highest percent, instead of sorting (as this causes some problems that i dont want)
now i just tried your script, but you know me, i could not get it to work LOL
could you explain it to me a different way please sparkout?
cheers
Posted: Thu Nov 05, 2009 11:11 am
by SparkOut
OK, say you have a field "Entries" with
Code: Select all
alvin brown novice 66
simon yellow intermediate 54
theodore crimson senior 42
dog red senior 23
sheep black intermediate 76
wildebeest tan novice 61
chipmunk purple senior 83
badger grey intermediate 23
gnu tan novice 51
Note that the spaces in between the values here should be tabs, so if you copy and paste to test, you'll need to replace the gaps with tabs to fill your table.
Not that you need to know for this particular answer, but sorting a container in RunRev is "non-destructive" - that is, if you sort by one element, then a subsequent sort on another element will preserve the order originally sorted within the first element. So we can do a numeric sort on the percentages (make sure they are stored in the table as numbers, not a "string" with a percent sign) and then do a sort on the "class" or "group", which will keep the ascending order of the percentages, but split between the groups.
Code: Select all
on mouseUp
--assuming a tab delimited table field with the numeric values in column 4
--and text "group names" in column 3
set the itemDelimiter to tab
sort lines of field "Entries" ascending numeric by item 4 of each
sort lines of field "Entries" ascending text by item 3 of each
end mouseUp
So
What happens if there is a tie? Apart from sorting you can check the values and highlight the results as you mentioned, but to give you code for that I'd like to know what you want to happen in the event of 88%, 88%, 79%, 79%, 76%, 76%, 76%, 74%, 71%, 71%, 68%, 66%, 63% etc being the scores.
Posted: Thu Nov 05, 2009 11:43 am
by smash
oh sparkout, that is way to confusing for me LOL
ok, i dont want any "sorting" as that just wont work for what i am trying to do.
i just want the top 10 percentages to be highlighted in 10 different coloums.
for example
50%
78%
65%
67.15%
88.5%
55.2%
61.9%
88.9%
88.5%
blue = first
red = second
orange = fourth
due to an equal second (red) there is no third.
see how it does not sort.
or if it is easier, to put a numeric number (like 1st, 2nd etc) into a column next to it
for example
column 4 column 5
50%
78% 4
65%
67.15%
88.5% 2
55.2%
61.9%
88.9% 1
88.5% 2
could either of these two examples be done ???
thanks sparkout
Posted: Thu Nov 05, 2009 11:45 am
by smash
mmm that second example was supose to be 2 coulmns.
but they keep going together????
Posted: Fri Nov 06, 2009 11:04 am
by Regulae
Hi there,
I thought I would have a go at the problem, which seems interesting. I don’t know if I have understood properly what you want, but for my script to work you identify the column you want to colour by loading the variable chosenColumn. It works on one column without changing the order. The script refers to the field by name at the start, and towards the end, so “TestTableâ€
Posted: Fri Nov 06, 2009 11:36 am
by smash
Regulae,
THAT IS PERFECT !!!!!!!!!!
thank you so much, off to study how that works, as i was no where near a script like that.
THANK YOU again
cheers[/b]
Posted: Fri Nov 06, 2009 12:56 pm
by Regulae
Hi Smash,
Hope things work for you. I meant to post an adjustment you will need, clearing previous highlights on a column, if you want to use the button repeatedly. The adjustment is:
Code: Select all
repeat with rowNumber = 1 to the number of lines in tableStore
put (item chosenColumn of line rowNumber of tableStore)&tab&rowNumber&return after extractedColumn
-- clear previous highlights in column
set the foregroundcolor of item chosenColumn of line rowNumber of card field "TestTable" to empty
end repeat
... you can see the line that I have added. It is the repeat right after
During testing, I simply reset the entire field, but this is more specific, and won't upset any other highlights.
Regards,
Michael
Posted: Fri Nov 06, 2009 1:10 pm
by smash
thank you so much Regulae,
that works such a treat, it was exactly what i was looking for.
just perfect !!!!!!!!!!!
THANK YOU
Posted: Fri Nov 06, 2009 1:15 pm
by Regulae
My pleasure! Thanks for an interesting challenge.
Posted: Fri Nov 06, 2009 1:38 pm
by smash
regulae,
i am just playing with your fantastic script (quiet mind blowing actually)
is there a way to add 1st ,2nd and 3rd to the column next to it automatically?? (by using your original script)
so for example, where ever the highest number is (that turns blue) in the next column (column 5) a "1st" would appear on the same line ?
Posted: Fri Nov 06, 2009 2:10 pm
by Regulae
I think this does what you want. Four lines are added- below is the whole script, with the new lines marked " --* " in their comments. Note that as well as clearing the highlight from the percentage column before applying it anew, it will also clear the next (right hand) column, that contains the "1st", "2nd", "3rd" each time it runs, so the right hand column really should be "dedicated" to its task. As you can see, identifying the spot to put the text is really quite simple- we have all the information we need. I have also made applying it a little easier. Give the name of the table field in the first line.
Code: Select all
on mouseUp
/* Identify the table field */
put "TestTable" into tableFieldName
put card field tableFieldName into tableStore
/* Identify the column number you want to colour */
put 4 into chosenColumn
-- extract the desired column, adding the line numbers, into variable
set the itemDelimiter to tab
repeat with rowNumber = 1 to the number of lines in tableStore
put (item chosenColumn of line rowNumber of tableStore)&tab&rowNumber&return after extractedColumn
-- clear previous highlights in column
set the foregroundcolor of item chosenColumn of line rowNumber of card field tableFieldName to empty
put empty into item (chosenColumn + 1) of line rowNumber of card field tableFieldName
end repeat
replace "%" with empty in extractedColumn
-- sort the variable
sort numeric descending extractedColumn
/* Currently, we are colouring the top three percentages */
put 3 into rankLevels
put 1 into currentRank
put item 1 of line 1 of extractedColumn into currentTop
-- cycle through our list
set the lockScreen to true
repeat with rowNumber = 1 to the number of lines in extractedColumn
-- identify 1st, 2nd, 3rd rank- stop when we reach 4th rank
if item 1 of line rowNumber of extractedColumn < currentTop then
put item 1 of line rowNumber of extractedColumn into currentTop
put currentRank + 1 into currentRank
-- once we have coloured the top three ranks, we can stop
if currentRank > rankLevels then
exit repeat
end if
end if
-- using the line numbers of the top three ranks, we can colour them
put (item 2 of line rowNumber of extractedColumn) into lineToColor
if currentRank = 1 then
set the foregroundcolor of item chosenColumn of line lineToColor of card field tableFieldName to blue
put "1st" into item (chosenColumn + 1) of line lineToColor of card field tableFieldName
end if
if currentRank = 2 then
set the foregroundcolor of item chosenColumn of line lineToColor of card field tableFieldName to green
put "2nd" into item (chosenColumn + 1) of line lineToColor of card field tableFieldName
end if
if currentRank = 3 then
set the foregroundcolor of item chosenColumn of line lineToColor of card field tableFieldName to red
put "3rd" into item (chosenColumn + 1) of line lineToColor of card field tableFieldName
end if
end repeat
end mouseUp
Posted: Fri Nov 06, 2009 8:37 pm
by smash
that works PERFECTLY regulae.
what a great script
THANK YOU !!!
i just cant thank you enough.
THANK YOU
Posted: Fri Nov 06, 2009 10:55 pm
by smash
morning regulae,
now, this is the script i have, that works like a gem,
on mouseUp
/* Identify the table field */
put "Entries" into tableFieldName
put card field tableFieldName into tableStore
/* Identify the column number you want to colour */
put 4 into chosenColumn
-- extract the desired column, adding the line numbers, into variable
set the itemDelimiter to tab
repeat with rowNumber = 1 to the number of lines in tableStore
put (item chosenColumn of line rowNumber of tableStore)&tab&rowNumber&return after extractedColumn
-- clear previous highlights in column
set the foregroundcolor of item chosenColumn of line rowNumber of card field tableFieldName to empty
put empty into item (chosenColumn + 1) of line rowNumber of card field tableFieldName
end repeat
replace "%" with empty in extractedColumn
-- sort the variable
sort numeric descending extractedColumn
/* Currently, we are colouring the top three percentages */
put 12 into rankLevels
put 1 into currentRank
put item 1 of line 1 of extractedColumn into currentTop
-- cycle through our list
set the lockScreen to true
repeat with rowNumber = 1 to the number of lines in extractedColumn
-- identify 1st, 2nd, 3rd, 4th rank- stop when we reach 34th rank
if item 1 of line rowNumber of extractedColumn < currentTop then
put item 1 of line rowNumber of extractedColumn into currentTop
put currentRank + 1 into currentRank
-- once we have coloured the top three ranks, we can stop
if currentRank > rankLevels then
exit repeat
end if
end if
-- using the line numbers of the top three ranks, we can colour them
put (item 2 of line rowNumber of extractedColumn) into lineToColor
if currentRank = 1 then
set the foregroundcolor of item chosenColumn of line lineToColor of card field tableFieldName to blue
put "1st" into item (chosenColumn + 1) of line lineToColor of card field tableFieldName
end if
if currentRank = 2 then
set the foregroundcolor of item chosenColumn of line lineToColor of card field tableFieldName to red
put "2nd" into item (chosenColumn + 1) of line lineToColor of card field tableFieldName
end if
if currentRank = 3 then
set the foregroundcolor of item chosenColumn of line lineToColor of card field tableFieldName to green
put "3rd" into item (chosenColumn + 1) of line lineToColor of card field tableFieldName
end if
if currentRank = 4 then
set the foregroundcolor of item chosenColumn of line lineToColor of card field tableFieldName to empty
put "4th" into item (chosenColumn + 1) of line lineToColor of card field tableFieldName
end if
if currentRank = 5 then
set the foregroundcolor of item chosenColumn of line lineToColor of card field tableFieldName to empty
put "5th" into item (chosenColumn + 1) of line lineToColor of card field tableFieldName
end if
if currentRank = 6 then
set the foregroundcolor of item chosenColumn of line lineToColor of card field tableFieldName to empty
put "6th" into item (chosenColumn + 1) of line lineToColor of card field tableFieldName
end if
if currentRank = 7 then
set the foregroundcolor of item chosenColumn of line lineToColor of card field tableFieldName to empty
put "7th" into item (chosenColumn + 1) of line lineToColor of card field tableFieldName
end if
if currentRank = 8 then
set the foregroundcolor of item chosenColumn of line lineToColor of card field tableFieldName to empty
put "8th" into item (chosenColumn + 1) of line lineToColor of card field tableFieldName
end if
if currentRank = 9 then
set the foregroundcolor of item chosenColumn of line lineToColor of card field tableFieldName to empty
put "9th" into item (chosenColumn + 1) of line lineToColor of card field tableFieldName
end if
if currentRank = 10 then
set the foregroundcolor of item chosenColumn of line lineToColor of card field tableFieldName to empty
put "10th" into item (chosenColumn + 1) of line lineToColor of card field tableFieldName
end if
if currentRank = 11 then
set the foregroundcolor of item chosenColumn of line lineToColor of card field tableFieldName to empty
put "11th" into item (chosenColumn + 1) of line lineToColor of card field tableFieldName
end if
if currentRank = 12 then
set the foregroundcolor of item chosenColumn of line lineToColor of card field tableFieldName to empty
put "12th" into item (chosenColumn + 1) of line lineToColor of card field tableFieldName
end if
end repeat
end mouseUp
now, i do not know how to format (or word correctly) that if there is an equal, how to skip to the next rank
eg
equal second, means there is no third, so then goes to forth
79 = 2nd
79.1 = 1st
79 = 2nd
78 = 4th
this has been a great learning curve, as this is the first time, that i have found, that columns can be selected (just been months and months of trying to work that out)

so thank you so much