Misconception on my part
correct with
#Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven 11}
{empty -1}]
for
#Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven 11}
{empty ""}]
I have to write a sort command.
Am 03.04.24 um 06:03 schrieb greg:
Misconception on my part
correct with
#Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
11} {empty -1}]
for
#Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
11} {empty ""}]
This correction eliminates the error message because all *internal* cell values of the column "Number" are now integers.
I have to write a sort command.
Why? For the column "Number" no sort command is needed.
Am 03.04.24 um 11:26 schrieb nemethi:
Am 03.04.24 um 06:03 schrieb greg:
Misconception on my part
correct with
#Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
11} {empty -1}]
for
#Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
11} {empty ""}]
This correction eliminates the error message because all *internal*
cell values of the column "Number" are now integers.
I have to write a sort command.
Why? For the column "Number" no sort command is needed.
1)
set col 1
$tbl columnconfigure $col -formatcommand formatNumber
# Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven 11}
{empty -1}]
sorts the 11 between 1 and 2
2)
set col 1
$tbl columnconfigure $col -formatcommand formatNumber -sortmode integer
# Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven 11}
{empty -1}]
#sorts ok
But if I need the values from column Number for a summation, I cannot
use this method. Then I have an incorrect sum with the substitute values
for "".
Hence a proc for it
proc customCompare {a b} {
# Treat empty cells as very large so they will be sorted at the end
if {$a eq ""} {set a 999999}
if {$b eq ""} {set b 999999}
# Convert to numbers and compare
set numA [expr {int($a)}]
set numB [expr {int($b)}]
if {$numA < $numB} {
return -1
} elseif {$numA > $numB} {
returns 1
} else {
return 0
}
}
Am 03.04.24 um 20:56 schrieb greg:
Am 03.04.24 um 11:26 schrieb nemethi:
Am 03.04.24 um 06:03 schrieb greg:
Misconception on my part
correct with
#Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
11} {empty -1}]
for
#Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
11} {empty ""}]
This correction eliminates the error message because all *internal*
cell values of the column "Number" are now integers.
I have to write a sort command.
Why? For the column "Number" no sort command is needed.
1)
set col 1
$tbl columnconfigure $col -formatcommand formatNumber
# Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
11} {empty -1}]
sorts the 11 between 1 and 2
2)
set col 1
$tbl columnconfigure $col -formatcommand formatNumber -sortmode integer
# Data
$tbl insertlist end [list {one 1} {two 2} {three 3} {four 4} {eleven
11} {empty -1}]
#sorts ok
But if I need the values from column Number for a summation, I cannot
use this method. Then I have an incorrect sum with the substitute
values for "".
Hence a proc for it
proc customCompare {a b} {
# Treat empty cells as very large so they will be sorted at the end
if {$a eq ""} {set a 999999}
if {$b eq ""} {set b 999999}
# Convert to numbers and compare
set numA [expr {int($a)}]
set numB [expr {int($b)}]
if {$numA < $numB} {
return -1
} elseif {$numA > $numB} {
returns 1
} else {
return 0
}
}
Why not use a summation proc rather than a comparison one? You could
write a simple proc that adds the internal cell values, except that it
skips the value -1 (or 999999) when building the sum.
Sysop: | DaiTengu |
---|---|
Location: | Appleton, WI |
Users: | 916 |
Nodes: | 10 (0 / 10) |
Uptime: | 00:38:07 |
Calls: | 12,172 |
Calls today: | 2 |
Files: | 186,522 |
Messages: | 2,234,815 |