mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Apr 2003
Posts: 426
Fjord artisan
OP Offline
Fjord artisan
Joined: Apr 2003
Posts: 426
This is fscking irritating.


How can I sort a numerical drop list properly.

Using the sort option basically sorts numbers like this:

120
15
180
20
25
30

etc...


This is damn frustrating!

(I don't want to have to manually specify the order to list them properly)


--------
mIRC - fun for all the family (except grandma and grandpa)
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
/filter the contents, instead of using the sort prop.
filter -iocut 1 32 DNAME ID DNAME ID

Joined: Apr 2003
Posts: 426
Fjord artisan
OP Offline
Fjord artisan
Joined: Apr 2003
Posts: 426
Actually, I want to be able to sort it numerically, as well as highlight the preset number, but still have it sorted numerically.

Last edited by neophyte; 24/05/03 06:54 AM.

--------
mIRC - fun for all the family (except grandma and grandpa)
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
If I understood what you want, you can do something like this (let's assume that you want to add number 42 to the listbox of ID 5 on the dialog named "foo"):
Code:
  ...
  did -a foo 5 42
  filter -iocut foo 5 foo 5
  did -c foo 5 $didwm(foo,5,42)
  ...


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: May 2003
Posts: 11
R
Pikka bird
Offline
Pikka bird
R
Joined: May 2003
Posts: 11
you problem comes for mirc treating the numbers as text not numbers. So when it goes to sort and look at 120 and 15, it goes left to right. for example 1 = 1, 2 < 5; so 120 goes before 15. my best suggestion for getting around this is by using a nested for loop (aka a while loop with an incrementing variable (mirc, wheres the for loop?!)) and forcing mirc to treat the text as a number by using a command like $int.

so heres an example:

alias sort {
var %i = 0
var %j = 0
while ( %i < $did($dname,listid).lines ) {
while ( %j < $did($dname,listid).lines ) {
if ( $int($did($dname,listid,%i).text) < $int($did($dname,listid,%j).text) {
var %temp = $did($dname,listid,%i).text
did -o $dname listid %i $did($dname,listid,%j).text
did -o $dname listid %j %temp
}
inc %j
}
inc %i
}
}

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
You have a misunderstanding on how mirc works.

1) There is no need for this terribly slow alias (nested while loops in mirc = slow when the number of items is fairly large), since we already demonstrated the way to do a numeric sorting, and that's /filter with the -t and -u switches.

2) Even if there was no other way of doing a numeric sort, those $int()'s aren't necessary. The final comparison (with >) is done on the evaluated content of $int(): whenever the > operator (internally) is used for comparing two items, it does not know where those items came from, ie whether they were a result of the evaluation of $int() or $round() or a %variable etc. Apparently, all mirc identifiers/variables are evaluated starting from the deepest ones and all the intermediate results are passed as strings, until all evaluation is done. Then mirc executes the command that used them (be it an /if command-statement, or another mirc /command), without remembering where the (evaluated) parameters came from: they are all strings internally.
Apart from that, in an "if (v1 > v2)" statement, the > operator treats v1 and v2 as numbers, if they are. Only if they are non-numbers does mirc treat them as text and does a "sort" comparison. Obviously, at some point, the two parameters around the > operator (which are always strings resulting from the evaluation of identifiers/variables) are converted to numbers internally. All the scripter notices (and cares about) is that the script operator > treats v1 and v2 as numbers, whether they have decimals or not.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com

Link Copied to Clipboard