mIRC Home    About    Download    Register    News    Help

Print Thread
#119387 05/05/05 12:55 AM
Joined: Jan 2005
Posts: 25
A
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Jan 2005
Posts: 25
hey guys, i need help on recovering from an error. See this code:
Code:
 
/test {
  var %m = $lines(t.txt),%i = 1
  fopen t t.txt
  while (%i <= %m) {
    var %l = $fread(t)
    echo -s %i = %l
    :nxt
    inc %i
  }
  fclose t
  return
  :error
; i assume that d only error would be a 'line too long'
  echo -s line too long: %i
  goto nxt
}
 

i intentionally put a 999-char line in t.txt. i need for the alias to keep going with the loop after printing an error msg

thnx in advance wink


- I AM -
#119388 05/05/05 01:53 AM
Joined: Dec 2002
Posts: 1,245
M
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
you can't mix the loop types like that
the goto nxt will never work as that loop has already exited
you dont need to fopen the file
Quote:

/test {
var %m = $lines(t.txt),%i = 1
while (%i <= %m) {
echo -s %i = $read(t.txt,%i)
inc %i
}
}


you should see an error msg if there is one for line too long anyway

#119389 05/05/05 02:07 AM
Joined: Jan 2005
Posts: 25
A
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Jan 2005
Posts: 25
uhm.. thnx for the input, but i think u misunderstood me blush my problem is this:

when an error occurs (in this case, a 'line too long..') it HALTS the script. in the case of the alias i posted above, the loop doesnt get to finish /echo'ing the whole file. what i need is to be able to carryout the rest of the loop even if it encounters and error. (something like VBs' On Error Resume Next statement wink)

side note: /fopen & $fread makes things up A WHOLE LOT FASTER than using $read. wink


- I AM -
#119390 05/05/05 02:43 AM
Joined: Sep 2004
Posts: 200
I
Fjord artisan
Offline
Fjord artisan
I
Joined: Sep 2004
Posts: 200
i assume that
/test {
var %m = $lines(t.txt),%i = 1
fopen t t.txt
while (%i <= %m) {
var %l = $fread(t)
echo -s %i = %l
goto finish
:error
echo -s line too long: %i
:finish
inc %i
}
fclose t
return
}
would work smile

Last edited by IR_n00b; 05/05/05 02:44 AM.
#119391 05/05/05 02:51 AM
Joined: Jan 2005
Posts: 25
A
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Jan 2005
Posts: 25
sorry man, tried it, but doesnt work smirk
the echo -s Error .. part doesnt even trigger.


- I AM -
#119392 05/05/05 03:59 AM
Joined: Sep 2004
Posts: 200
I
Fjord artisan
Offline
Fjord artisan
I
Joined: Sep 2004
Posts: 200
lets make somthing creative..

/test {
var %m = $lines(t.txt),%i = 1
fopen t t.txt
while (%i <= %m) {
var %l = $fread(t)
echo -s %i = %l
goto finish
:error
echo -s line too long: %i
:finish
inc %i
}
fclose t
return
}

goes to:
/test {
var %m = $lines(t.txt),%i = 1
fopen t t.txt
:loop
while (%i <= %m) {
var %l = $fread(t)
echo -s %i = %l
inc %i
}
goto close
:error
echo -a Error: /var line to long: %1
goto loop
:close
fclose t
return
}

#119393 05/05/05 04:28 AM
Joined: Jan 2005
Posts: 25
A
Ameglian cow
OP Offline
Ameglian cow
A
Joined: Jan 2005
Posts: 25
Hey! Great job! ;D Works great! i did have to squeeze in an
inc %i so that the count goes up properly, but damn does it work! ;D thnx a million ;D


- I AM -

Link Copied to Clipboard