Author Topic: Get current script line number  (Read 282 times)

kifrostit

  • Newbie
  • *
  • Posts: 1
Get current script line number
« 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)


JTaylor

  • Pundit
  • *****
  • Posts: 748
    • Data & Stuff Inc.
Re: Get current script line number
« Reply #1 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

stanl

  • Pundit
  • *****
  • Posts: 630
Re: Get current script line number
« Reply #2 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.

td

  • Tech Support
  • *****
  • Posts: 2141
    • WinBatch
Re: Get current script line number
« Reply #3 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.

"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


td

  • Tech Support
  • *****
  • Posts: 2141
    • WinBatch
Re: Get current script line number
« Reply #4 on: June 01, 2017, 07:01:31 am »
A possible approach.

Code: Winbatch
; 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
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates