WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Winbatch Studio
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Interactive Debug Mode and GoSub

 Keywords:  interactive debug debugging winbatch studio mode gosub

Question:

If I run these two scripts everything works fine with compiled main.exe, but it is impossible to debug in Studio, because label :Sub is not visible in Studio when debugging Main. I am running 2002b.
Main.wbt:
#include Subs_And_Funcs.wbt
Message("Func returned",Func())
GoSub Sub
Message("Subroutine returned",val)
exit

Subs_And_Funcs.wbt:
goto Define_Functions
:Sub
	val = "Subroutine called"
return
:Define_Functions
#DefineFunction Func()
	return "Function called"
#EndFunction

How can I debug this code?

Answer:

Ah Yes. When you attempt to run your script in interactive debug mode and it has a #include statement, WB Studio must act as though your making a call using the Call function. This means that none of the variable space is shared. So when you attempt to 'Gosub' in the the 'called' file you get an error. Inorder to debug into a 'called' WinBatch script or user defined function, you must make sure to add a debug command, to the 'called script' or user defined function.

In summary, If you want to debug a script that has a #Include statement and it attempts a gosub into the included file, you should use the DebugTrace function instead. I have included an example that should help:

Make sure to choose the 'RUN' option, to run the following script from WinBatch studio:

;Main.WBT
dbg = @ON ; to turn of debug set to @OFF
If dbg = @ON then DebugTrace(@On,"C:\trace.txt")
#include Subs_And_Funcs.wbt
Message("Func returned",Func())
GoSub Sub
Message("Subroutine returned",val)
Exit

;Subs_And_Funcs.wbt
If dbg = @ON then DebugTrace(@On,"C:\trace.txt")
goto Define_Functions
:Sub
	val = "Subroutine called"
return
:Define_Functions
#DefineFunction Func()
     If dbg = @ON then DebugTrace(@On,"C:\trace.txt")
	return "Function called"
#EndFunction

Article ID:   W15349
File Created: 2002:09:05:13:51:26
Last Updated: 2002:09:05:13:51:26