mIRC Homepage
Posted By: Revy read from file and give x results - 08/01/07 12:43 AM
Hello, I want to search something on a text file and message the results (max 5 results) on the channel.

I already did this code (see below) , but this code only gives me 1 result no more, even if I have more than 1 result on the text file.

Code:
on *:TEXT:*:#chan:{
  if ($1 == !search) && ($2 != $null) {
    set %ress $read(file.txt, w, $replace(* $+ $2- $+ *,$chr(32),*) )
    if (%ress != $null) {
    .timerM 1 1 msg #chan %ress }
    else { .timerM 1 1 msg #chan Nothing Found
    }
  }
}


What can I do to modify the code to give me X results?

Thanks
Posted By: billythekid Re: read from file and give x results - 08/01/07 12:54 AM
you could use a /filter to pull all lines containing *whatever* then return those...

Code:
on *:TEXT:*:#chan:{
  if ($1 == !search) && ($2 != $null) {
    write -c results.txt
    filter -ff file.txt results.txt $replace(* $+ $2- $+ *,$chr(32),*)  
    if ($filtered) {
      var %i = 0
      while %i < 5 {
        inc %i
        msg $chan $read(results.txt,n,%i)
      }
    }
    else { msg #chan Nothing Found }
  }
}


Posted By: xDaeMoN Re: read from file and give x results - 08/01/07 12:57 AM
Try this, made by Quickstep
Code:
on *:TEXT:!search*:#:{
  ;-------- Set these vars --------
  var %file = FILE.txt, %maxsend = 5
  ;--------------------------------

  ;------- Code --------
  var %a = 1, %s = $+(*,$2-,*)
  :again
  if ($read(%file, nw, %s, $calc($readn + 1))) {
    tokenize 32 $ifmatch   
    if (%a <= %maxsend) msg # Match $+(no.,$v1) Link: $1 Description: $2-
    inc %a
  }
  if ($readn) goto again
  $iif(%a > %maxsend,msg # A total of $v1 matches were found only $v2 were displayed)
  $iif(!%a,msg # No matches found)
  ;---------------------
}
Posted By: Revy Re: read from file and give x results - 08/01/07 02:15 AM
Thanks for all the answers, it's working now laugh
© mIRC Discussion Forums