mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Dec 2015
Posts: 2
B
Bldjef Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
B
Joined: Dec 2015
Posts: 2
I'm trying to build a simple dialog which reads and write to a text file.
It's all working, but the only problem occurs when I'm trying to insert multiple lines in the edit box of the dialog. I thought I could solve it with the "multi return" option, but that didn't work.

Also, I'm still working on how to read all lines and display it in the edit box, because you can't store more lines in a variable, right?

Code:
alias info {
  set %info $read(info.txt)
  dialog -m Info Inf  
}

dialog Info {
  title Info
  size -1 -1 150 110
  option dbu
  edit %info , 1 , 10 10 130 80,multi return
  button "Done", 3, 10 95 40 12, ok
}

on *:dialog:Info:close:*:{
  write -c Info.txt
  write info.txt $did(UserInfo,1).text

Joined: Dec 2008
Posts: 1,515
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2008
Posts: 1,515
Try use this code:

Code:
dialog Info {
  title Info
  size -1 -1 150 110
  option dbu
  edit , 1 , 10 10 130 80,multi return
  button "Done", 3, 10 95 40 12, ok
}

ON *:DIALOG:info:*:*: {
  if ($devent == init) { load_file }
  if ($devent == close) { save_file }
}

alias -l load_file {
  var %f = info.txt
  if (!$isfile(%f)) { return }
  if (!$lines(%f)) { return }
  var %t = $lines(%f)
  var %i = 1
  while (%i <= %t) { 
    var %l = $read(%f,%i)
    if (%l) { did -a $dname 1 %l $+ $crlf }
    inc %i
  }
}
alias info { dialog -m Info Info }
alias -l save_file {
  var %t = $did($dname,1).lines
  if (!%t) { return }
  var %f = info.txt
  if ($isfile(%f)) { .remove $qt(%f) }
  var %i = 1
  while (%i <= %t) {
    var %l = $did($dname,1,%i).text
    if (%l) { write $qt(%f) %l }
    inc %i
  }
}


Need Online mIRC help or an mIRC Scripting Freelancer? -> https://irc.chathub.org <-
Joined: Dec 2015
Posts: 2
B
Bldjef Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
B
Joined: Dec 2015
Posts: 2
Awesome, thanks!! laugh

Joined: Dec 2015
Posts: 148
Vogon poet
Offline
Vogon poet
Joined: Dec 2015
Posts: 148
I would recommend using /loadbuf and /savebuf instead of reading and writing the lines one by one. It's a lot faster and looks prettier.

Code:
dialog info {
  title Info
  size -1 -1 150 110
  option dbu
  edit , 1 , 10 10 130 80, multi return
  button "Done", 3, 10 95 40 12, ok
}

alias info dialog $iif($dialog(info),-c,-m) info info

on *:dialog:info:*:*: {
  if ($devent == init) && ($isfile(info.txt)) loadbuf -o info 1 info.txt
  elseif ($devent == close) savebuf -o info 1 info.txt
}

Last edited by Dazuz; 31/12/15 03:09 PM.

Link Copied to Clipboard