WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: kdmoyers on February 12, 2025, 11:58:50 AM

Title: Variables Window behavior
Post by: kdmoyers on February 12, 2025, 11:58:50 AM
You know how the variables window will show the contents of an array?
Great stuff.  Super helpful in debugging.

You know how it refuses to do that if your program stops at any error?
Not so great.  Work-around-able, but that becomes a sub-project itself.

It says "cannot modify items or view arrays" after script has completed, but the reason we can't at least see the array is not obvious.  If this limitation could be removed, it would be super.

Maybe add it to the Big List of Things?

In the mean time, here's a little function to dump a 2d array to debugdata.  If you sprinkle this around where you think the error condition can arise, then you might see what the array had in it at the time of the error.

#definefunction debugarray(tag,array)
if arrinfo(array,0)==2 ; for 2d arrays
for _i = 0 to arrinfo(array,1)-1
s = tag:"  ":_i:": "
for _j = 0 to arrinfo(array,2)-1
s := array[_i,_j] :" | "
next _j
debugdata("",s)
next _i
endif
#endfunction

You can use the wonderful DebugView program ( https://learn.microsoft.com/en-us/sysinternals/downloads/debugview ) to view this output in another window.
Title: Re: Variables Window behavior
Post by: td on February 12, 2025, 01:32:03 PM
You cannot view arrays after a script error because the array variable no longer exists in memory when a script terminates. Since the script terminated, there would be no reason to edit the variable contents anyway.

I usually drop a breakpoint in the breakpoint gutter just before the line causing the error or add a breakpoint command to the script at the appropriate spot. That way I at least know what the contents leading to the error are.
Title: Re: Variables Window behavior
Post by: td on February 13, 2025, 08:08:52 AM
Here is another approach.

; When using WBS debugger.
if RtStatus() == 10 then IntControl(73,2,0,0,0)
a = ArrayFromStr("abc")
; Cause an error.
novalue = a[3]
exit
; Error handler with breakpoint.
:WBERRORHANDLER
   breakpoint
return  ; Don't forget to continue so you exit the debugger.
Title: Re: Variables Window behavior
Post by: kdmoyers on February 13, 2025, 12:08:09 PM
Quote from: td on February 12, 2025, 01:32:03 PMSince the script terminated, there would be no reason to edit the variable contents anyway.
Oh for sure, for sure, no editing.  I just wanted to SEE the contents of the array.

And yes, what I do is narrow down the conditions that will cause the error and using breakpoint stop just before that.  It gets tricky when the contents of the array itself is the problem.  That's why it would be handy to see it after the error.

But your idea of putting breakpoint inside :wberrorhandler is wonderfully clever. This will work for me! Thanks man!!
Title: Re: Variables Window behavior
Post by: kdmoyers on February 13, 2025, 12:24:24 PM
Yes! it works great!  Kinda bummed I did not think of it myself.