This project has moved and is read-only. For the latest updates, please go here.

Fetch all the Variables and their values

Jun 28, 2015 at 1:43 PM
Edited Jun 28, 2015 at 1:44 PM
I am implementing a debugger for Vbscript which is expected to display all the variables and their values upon hitting break point.

I am able to fetch all the variables using following code:
public static VBScriptEngine engine;
public static JScriptEngine engine1;

dynamic ome = engine.Evaluate("me");

engine1.Evaluate("Enum=function(x){this.x=new Array();for (var i in x) {this.x[i]=i};return this.x}");
        dynamic ojas = Script.engine1.Evaluate("this");
dynamic x = ojas.Enum(ome);

The challenge here i am facing is that i am not able to fetch the context specific variables:
A break point is set inside a function then upon hitting the break-point the variable list gets empty as per the above code.

Is there a way to fetch the context specific variables also(the variables inside the function)

Consider the following code:
abc = 123

def = 1432
Call hello()

Function hello()



ja = 14

End Function

Here on hitting the breakpoint it should display jas = 123

Please help!
Jun 29, 2015 at 2:44 PM

Unfortunately there's no simple way to enumerate VBScript local variables. However, like most Windows Script engines, VBScript plugs into the Windows debugging infrastructure and therefore supports debugging via Visual Studio and other debuggers. Creating a custom debugger for this framework is possible, but it's a large undertaking, and unfortunately the interfaces are not well documented. You can find an overview here.

By the way, there's no need to use JavaScript to enumerate the properties of a VBScript object. This is something ClearScript lets you do directly from .NET:
dynamic ome = engine.Evaluate("me"); // or engine.Script
foreach (var name in ome.GetDynamicMemberNames())
    Console.WriteLine("{0}: {1}", name, ome[name]);
Good luck!
Jul 1, 2015 at 6:40 AM
Thanks for the reply.

So can you please suggest me a way to have variables in Microsoft Script Debugger and how do i run the script in debug mode?

much Thanks!
Jul 1, 2015 at 3:23 PM
Hi again,

You can enable script debugging in your VBScript instances by passing WindowsScriptEngineFlags.EnableDebugging to the VBScriptEngine constructor. You should then be able to attach Visual Studio or another debugger to your running application for script debugging.

Another way to attach a debugger is to insert a VBScript stop statement somewhere in the script code. When VBScript executes this statement, a dialog will appear giving you the opportunity to launch or attach a script debugger paused at that point in the script.

Good luck!
Jul 8, 2015 at 5:15 AM
Thanks for the inputs!