mIRC Home    About    Download    Register    News    Help

Print Thread
Dialog Listbox Help #91804 26/07/04 07:09 AM
Joined: Apr 2004
Posts: 66
C
Cyrex Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Apr 2004
Posts: 66
How can I make numbers appear unsorted in a list box after doing a while loop? I have a dialog that has a list box, and when I click on the "Loop" button, it will generate a number list from 1 - 9999, then it displays the numbers in the list box. That works fine, but I want the numbers to appear in random order in the listbox instead of in numeric order.


Here's my code:

Code:

dialog loop {
  title "Loop test"
  size -1 -1 79 104
  option dbu
  list 1, 3 3 72 83, size
  button "Loop", 2, 21 89 37 12
  button "", 3, 0 0 0 0, hide cancel
}

on *:dialog:loop:sclick:2:{
  did -r $dname 1
  did -b $dname 2
  var %i = 1
  while (%i <= 9999) {
    did -a $dname 1 $ifmatch
    inc %i
  }
 did -e $dname 2 
}


Re: Dialog Listbox Help #91805 26/07/04 11:22 AM
Joined: Aug 2003
Posts: 314
S
Sigh Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2003
Posts: 314
You can randomize it by again looping through the lines and moving them to a hidden window, then filtering that window to the dialog list:

alias loop {
if ($window(@Loop)) { window -c @Loop }
window -h @Loop
var %r,%x = 9999
while (%x) {
%r = $r(1,$did(loop,1).lines)
echo @Loop $did(loop,1,%r)
did -d loop 1 %r
dec %x
}
filter -cwo @Loop loop 1
}

Ensure that in your options you allow at least 9999 lines for a buffer capacity so the custom window can hold all the lines of the dialog list

Re: Dialog Listbox Help #91806 26/07/04 06:37 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Code:
on *:dialog:loop:sclick:2:{
  did -r $dname 1
  did -b $dname 2
  var %i = 1
  while (%i <= 9999) {
    did [color:red]-i[/color] $dname 1 [color:red]$r(1,%i)[/color] %i
    inc %i
  }
  did -e $dname 2 
}


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: Dialog Listbox Help #91807 26/07/04 07:23 PM
Joined: Apr 2004
Posts: 66
C
Cyrex Offline OP
Babel fish
OP Offline
Babel fish
C
Joined: Apr 2004
Posts: 66
Isn't there a possibility of numbers being repeated by using the $r() identifier? I thought I remember reading before that $r() is not always random. I am also not trying to generate random numbers, I am just trying to generate a list of numbers from 1 - 9999, no repeats. And I don't want the numbers to appear in numeric order...

Re: Dialog Listbox Help #91808 26/07/04 11:11 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
$r() in the script isn't the <text> part, it's the <position> parameter, ie it tells /did -i where to insert %i, which is the <text>. So all numbers from 1 to 9999 get to be added, by a series of insertions at a random position. Btw, the syntax of the command is
/did -i <dname> <id> <pos> <text>


Quote:
I thought I remember reading before that $r() is not always random.
$rand() has been fixed since v 6.1, so this isn't true anymore. Even in versions prior to 6.1 though, that particular $rand bug in this particular script would affect the 'randomness' of the distribution VERY little (explaining that would require a lengthy analysis, which I won't get into here).



/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Re: Dialog Listbox Help #91809 27/07/04 08:42 AM
Joined: Jul 2004
Posts: 1
B
bi0s_BR Offline
Mostly harmless
Offline
Mostly harmless
B
Joined: Jul 2004
Posts: 1
Hey, u can use this:


dialog loop {
title "Loop test"
size -1 -1 79 104
option dbu
list 1, 3 3 72 83, size
button "Loop", 2, 21 89 37 12
button "", 3, 0 0 0 0, hide cancel
}
on *:dialog:loop:sclick:2:{
while ($did($dname,1).lines < 9999) {
var %a $r(1,9999)
if (!$didwm($dname,1,%a)) { did -a $dname 1 %a }
}
}


but the speed.. is sucks frown