WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: kifrostit on May 30, 2017, 02:30:27 PM

Title: Get current script line number
Post by: kifrostit on May 30, 2017, 02:30:27 PM
Is there a way to get a compiled scriptââ,¬â,,¢s current executing line number during runtime that is not part of error handling?
So instead of doing something line below:
Display(5,"ProgramName line 229",original)    ; for debugging and if your script changes, then the Display is no longer valid
I would like to do something like:
LineNumber=SomeFunction()  or reserved variable or constant
Display(5,"ProgramName line %LineNumber%",original)

Title: Re: Get current script line number
Post by: JTaylor on May 30, 2017, 07:20:05 PM
I am curious...If you are willing to answer, to what use would you put such a feature?

Jim
Title: Re: Get current script line number
Post by: stanl on May 31, 2017, 03:08:19 AM
I'm also curious. If it is a compiled script and runs as an EXE and you want the line being executed not part of the error handler - how would you control that?  Certainly not with display() as that would resemble a weak step-through.
Title: Re: Get current script line number
Post by: td on May 31, 2017, 08:13:31 AM
As already alluded to that sort  feature has limited  usefulness.

However, a way to implement the behavior would be to generate and trap a minor error.  You could then obtain the line number from the error information.   Or you could simply devise your own naming system for the desired check points within the script.   The latter is something that is done in some programming languages when a debugger is not available.

Title: Re: Get current script line number
Post by: td on June 01, 2017, 07:01:31 AM
A possible approach.

Code (winbatch) Select
; Error handler UDF.
#DefineFunction DisplayLineNo(_e)
   Display(2,'Line Nunber',_e[8]-2)
#EndFunction

;Blah blah blah

; Script lines here...
x = 1 

; Point were you want a line number
IntControl(73,3,1,'DisplayLineNo',0)
CauseError =

exit