1

Is there any way to fetch all the variable values in the script at runtime.

Consider the following vbscript code.

var1= 5
Var2= 6

For i=0 To 5
   Msgbox i
Next

How do i Implement it using msscript control that i should be able to retrieve all the variables at runtime?

I am looking to implement a debugger for vbscript can i have the list of all the variables at runtime like below.

var1=5
Var2=6
i=5

Any help on this would be much appreciated.

Thanks in advance!

1 Answer 1

1

Here you are! Save the code below as VBScript file:

' VBS code variables to be fetched from
sVBScriptDebug = _
    "var1= 5" & vbCrLf & _
    "Var2= 6" & vbCrLf & _
    vbCrLf & _
    "For i=0 To 5" & vbCrLf & _
    "   Msgbox i" & vbCrLf & _
    "Next"

' ScriptControl to be used for debug purposes
Set oScrCtlDebug = CreateObject("MSScriptControl.ScriptControl")
oScrCtlDebug.Language = "VBScript"
oScrCtlDebug.AddCode sVBScriptDebug
' Me object from debug script
Set oMeDebug = oScrCtlDebug.Eval("Me")

' ScriptControl for JScript utility function pushing all object's properties to array
Set oScrCtlUtil = CreateObject("MSScriptControl.ScriptControl")
oScrCtlUtil.Language = "JavaScript"
oScrCtlUtil.Eval("Enum=function(x){this.x=new Array();for (var i in x) {this.x[i]=i};return this.x}")
' Retrieve JScript this object
Set oJSGlobal = oScrCtlUtil.Eval("this")

' Cycle through all debug script Me object properties, that actually are fetched global scope variables
sRes = ""
For Each sVar In oJSGlobal.Enum(oMeDebug)
    sRes = sRes & sVar & "=" & oScrCtlDebug.Eval(sVar) & vbCrLf
Next
MsgBox sRes
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.