[英]Fetch all variable values in vbscript using msscript control
有什么方法可以在運行時獲取腳本中的所有變量值。
考慮下面的vbscript代碼。
var1= 5
Var2= 6
For i=0 To 5
Msgbox i
Next
如何使用msscript控件實現該功能,以便我應該能夠在運行時檢索所有變量?
我正在尋找為vbscript實現調試器的工具,我可以在運行時獲取所有變量的列表,如下所示。
var1=5
Var2=6
i=5
任何幫助,將不勝感激。
提前致謝!
這個給你! 將以下代碼另存為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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.