mIRC Home    About    Download    Register    News    Help

Print Thread
Help: txt file in list box #127945 18/08/05 06:57 PM
Joined: Aug 2004
Posts: 42
T
The_Only Offline OP
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Aug 2004
Posts: 42
Hello!
I've been working on a very stupid dialog and I need to fill the list box with data from a text file. I need every line in the text file to be a select line in the listbox, but without adding "did -a dialog id" into the beginning of the line... I wrote it once but all day I've been working on my computer (I had a system crash and a damaged hard drive grin) and I'm a bit tired but I need it as soon as possible and I couldn't find another way except to ask you guys.. I also have an "add" button and a "delete" button, but I don't want to allow dublicates when adding.

Thanks, and again sorry for disturbing you with such a question...

Re: Help: txt file in list box #127946 18/08/05 07:05 PM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Code:
On *:Dialog:dlg:init:0: {
  var %x = 1
  while (%x <= $lines(file.txt)) {
    did -a dlg ID $read(file.txt,%x)
    inc %x
  }
}


-Andy

Re: Help: txt file in list box #127947 18/08/05 07:21 PM
Joined: Aug 2004
Posts: 42
T
The_Only Offline OP
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Aug 2004
Posts: 42
lol... how can I be so silly... I was trying the same code but with adding some crap with tokenization wink

Edit: Oh and by the way, is there a way to make the vertical scrollbar work?

Thanks

Last edited by The_Only; 18/08/05 07:23 PM.
Re: Help: txt file in list box #127948 18/08/05 07:33 PM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
On second thoughts, this might be a bit more sufficient. It's my first try with File Handling, but I'm sure others who've encountered /fopen and /fclose can point us in the right direction if it's wrong..

Code:
alias test {
  var %x = $+(x,$ticks), %lines
  .fopen %x file.txt
  if ($ferr) { .fclose %x | return }
  if ($fopen(%x)) {
    while (!$feof) {
      %lines = $fread(%x)
      did -a dlg ID %lines
    }
    .fclose %x
  }
}


As for the scroll bar, could you show me the code for you dialog please and thanks? smile

-Andy

Re: Help: txt file in list box #127949 18/08/05 07:51 PM
Joined: Aug 2004
Posts: 42
T
The_Only Offline OP
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Aug 2004
Posts: 42
Of course smile
Here it is:
Code:
alias quit.manager {
  dialog -m quit.manager quit.manager
}
dialog quit.manager {
  title "Quit Manager"
  size -1 -1 401 353
  option pixels
  icon icon.ico, 0
  box "Stored Quit Messages", 1, 4 4 394 221
  list 2, 8 20 386 198, size hsbar vsbar
  box "Add or Remove Quit Message", 3, 4 228 394 67
  text "Quit Message:", 4, 8 248 70 16
  edit "", 5, 80 244 314 21, autohs limit 350
  button "Add Message", 6, 80 270 114 20
  button "Delete Message", 7, 200 270 114 20
  check "Include VS", 8, 324 270 70 20, disable
  button "Quit using selected message", 9, 4 304 146 25, default
  button "Set default message", 10, 154 304 106 25
  check "Set Random", 11, 264 304 68 25, push
  button "Okay", 12, 336 304 62 25, ok
  text "'Set Random' will use a random quit message every time you quit!", 13, 4 332 314 16
}
on *:dialog:quit.manager:init:0: {
  var %x = 1
  while (%x <= $lines(vsd\quit.vsd)) {
    .did -a $dname 2 $read(vsd\quit.vsd,%x)
    inc %x
  }
  if (%quit2 == Random) { did -c $dname 11 | did -b $dname 10 }
}
on *:dialog:quit.manager:sclick:2: {
  did -ra $dname 5 $did(2).seltext
}
on *:dialog:quit.manager:sclick:6: {
  if ($did(5)) {
    if ($read(vsd\quit.vsd,w,$did($dname,5))) {
      halt
    }
    write vsd\quit.vsd $did($dname,5)
    did -a $dname 2 $did(5)
    did -r $dname 5
  }
}
on *:dialog:quit.manager:sclick:7: {
  write -dw $+("*,$did(2,$did(2).sel),*") vsd\quit.vsd
  did -d $dname 2 $did(2).sel
  did -r $dname 5
}
on *:dialog:quit.manager:sclick:9: {
  quit $did(2).seltext
}
on *:dialog:quit.manager:sclick:10: {
  set %quit2 $did(2).seltext
}
on *:dialog:quit.manager:sclick:11: {
  if (%quit2 != Random) {
    set %quit2 Random
    did -b $dname 10
  }
  else {
    set %quit2
    did -e $dname 10
  }
}

It all works except for the scrollbar (vertical) smile

Re: Help: txt file in list box #127950 18/08/05 08:10 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
Filter or loadbuf will be better to populate the listbox, since they come with built-in flags to do just this kind of thing. That would also reduce the code to one single command. You can read up on how to do it in the help file. Basically it lets you specify a dialog name, and the id of the control where you want to filter to. I'm unsure as I don't have mIRC on this computer, but loadbuf probably offers the same functionality, if its just for loading a text file into a listbox.

Anyway, regardless, it's a good thing to get used to the file handling commands, as you surely have heard from some scripters on the boards, they are several times more efficient compared to the /write and $read constructs.


Gone.
Re: Help: txt file in list box #127951 19/08/05 09:30 PM
Joined: Aug 2004
Posts: 42
T
The_Only Offline OP
Ameglian cow
OP Offline
Ameglian cow
T
Joined: Aug 2004
Posts: 42
Maybe... but this works too doesn't it? smile
Ok, but how can I get the scrollbar work?