1

有没有办法在运行时获取脚本中的所有变量值。

考虑以下 vbscript 代码。

var1= 5
Var2= 6

For i=0 To 5
   Msgbox i
Next

我如何使用 msscript 控件实现它,我应该能够在运行时检索所有变量?

我正在寻找为 vbscript 实现调试器,我可以在运行时获得所有变量的列表,如下所示。

var1=5
Var2=6
i=5

对此的任何帮助将不胜感激。

提前致谢!

4

1 回答 1

1

给你!将以下代码另存为 VBScript 文件:

' 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
于 2014-09-01T21:42:51.340 回答