Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

ON BREAK LEAVE?

May
15,177
274
ON BREAK LEAVE - is it cool? Sometimes I get an error; sometimes I don't.

Code:
v:\> type zerotest.btm
setlocal
on break leave
do forever
    set ticks=%@winapi[kernel32,GetTickCount]
    if %@eval[%_do_loop MOD 10000] == 0 echo %_do_loop %ticks
enddo

v:\> zerotest.btm
10000 812419140
^C

v:\> zerotest.btm
10000 812426890
^C
TCC: V:\zerotest.btm [6]  Unknown command "leave"

v:\> zerotest.btm
10000 812481031
^C

v:\> zerotest.btm
^C
TCC: V:\zerotest.btm [6]  Unknown command "leave"

v:\>
 
It works if a delay is added;

Code:
@setlocal
@echo off
on break leave
do forever
    set ticks=%@winapi[kernel32,GetTickCount]
    if %@eval[%_do_loop MOD 10000] == 0 echo %_do_loop %ticks
    delay 5
enddo
endlocal

Proof;

Code:
R:\>zerotest.btm
^C

R:\>zerotest.btm
^C
 
So breaking from a delay leaves you inside the DO and breaking from the previous command doesn't (or something like that).
 
Does this work for you?

Code:
@setlocal
@echo off
on break gosub leave
do forever
    set ticks=%@winapi[kernel32,GetTickCount]
    if %@eval[%_do_loop MOD 10000] == 0 echo %_do_loop %ticks
enddo
endlocal
quit

:leave
if isinternal leave leave 
return

Joe
 
Does this work for you?

Code:
@setlocal
@echo off
on break gosub leave
do forever
    set ticks=%@winapi[kernel32,GetTickCount]
    if %@eval[%_do_loop MOD 10000] == 0 echo %_do_loop %ticks
enddo
endlocal
quit

:leave
if isinternal leave leave
return

Joe
Yes! Any idea why?
 
Nope.

Code:
TCC: V:\zerotest.btm [6]  Unknown command "leave"

I was wondering why LEAVE would be an unknown command.

It would appear that testing for the validity of the LEAVE command eliminates the error.

Maybe a Microsoft RTL error that has become an undocumented feature?

I'm sure @rconn will find out.

Joe
 
Back
Top