mIRC Home    About    Download    Register    News    Help

Print Thread
#204444 20/09/08 05:19 AM
Joined: Sep 2007
Posts: 109
K
kwell Offline OP
Vogon poet
OP Offline
Vogon poet
K
Joined: Sep 2007
Posts: 109
What can I do for the command while gives me the 10 first lines of a txt file without giving me an error if the txt file only contains 4,10 would be the maximum limit.
It only works if the file has more than 10 lines but it gives me error if it is less

Code:
if $strip($1) = !top {
  var %i = 1
  while %i <= 10 {
    msg #channel $read(archive.txt,%i)
    inc %i
  }


kwell #204446 20/09/08 12:02 PM
Joined: Nov 2006
Posts: 1,559
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Nov 2006
Posts: 1,559
You can either add an "there's a successfull read" condition to the "while N <= 10" statement you already have, or use the $lines identifier. I'd go for the first.

Code:
var %i = 1
while ((%i <= 10) && ($read(archives.txt,%i))) {
  msg #channel $v1
  inc %i
}

or e.g.

Code:
var %i = 1, %file = archives.txt, %max = $iif(($lines(%file) < 10),$v1,$v2)
while (%i <= %max) { 
  msg #channel $read(%file,%i)
  inc %i
}


[ Pitty that for the -l switch of the /play command, there's no second parameter, like -l1-10 laugh ]


Link Copied to Clipboard