VBS中的MSGbox随变量值更新

时间:2014-03-19 17:17:53

标签: vbscript

只是想知道如何让MSgbox显示变量的值,因为它会不断变化。基本上每次循环时都会添加一个数字。我想在不需要打开百万窗口的MSGbox中显示它

4 个答案:

答案 0 :(得分:6)

解决方法是使用PopUp

Set objShell = WScript.CreateObject("WScript.Shell")
For i = 1 To 3
    objShell.Popup i, 1, "AutoClose MsgBox Simulation", vbInformation+vbOKOnly
Next

这将在1秒后“自动关闭”MsgBox相似

答案 1 :(得分:3)

您无法使用默认的VBScript对话框元素执行此操作,例如MsgBoxWScript.EchoPopup。您需要使用Internet Explorer COM对象构建custom dialog

Set ie = CreateObject("InternetExplorer.Application")
ie.Navigate "about:blank"

While ie.ReadyState <> 4 : WScript.Sleep 100 : Wend

ie.ToolBar   = False
ie.StatusBar = False
ie.Width     = 300
ie.Height    = 200

ie.document.body.innerHTML = "<p id='msg'>0</p>"

Set style = ie.document.CreateStyleSheet
style.AddRule "p", "text-align: center;"

ie.Visible = True

i = 1
Do
  ie.document.getElementById("msg").innerText = i
  i = i + 1
  WScript.Sleep 2000
Loop Until i > 10

或使用HTA而不是普通的VBScript:

<head>
<title>Test</title>
<HTA:APPLICATION ID="oHTA"
  APPLICATIONNAME="Test"
  SCROLL="no"
>
</head>

<style type="text/css">
  p {text-align: center;}
</style>

<script language="VBScript">
  window.resizeTo 300, 200

  Set sh = CreateObject("WScript.Shell")

  Sub Window_onLoad
    For i = 1 To 10
      msg.innerText = i
      Sleep 2
    Next
  End Sub

  Sub Sleep(t)
    sh.Run "ping -n " & (t+1) & " 127.0.0.1", 0, True
  End Sub
</script>

<body>
<p id="msg">0</p>
</body>

答案 2 :(得分:2)

另一个解决方案,使用HTA窗口,没有临时文件:

dim window, i

set window = createwindow()
window.document.write "<html><body bgcolor=buttonface>Current loop is: <span id='output'></span></body></html>"
window.document.title = "Processing..."
window.resizeto 300, 150
window.moveto 200, 200

for i = 0 to 32767
    show i
    ' your code here
next

window.close

function show(value)
    on error resume next
    window.output.innerhtml = value
    if err then wscript.quit
end function

function createwindow()
    ' source http://forum.script-coding.com/viewtopic.php?pid=75356#p75356
    dim signature, shellwnd, proc
    on error resume next
    set createwindow = nothing
    signature = left(createobject("Scriptlet.TypeLib").guid, 38)
    set proc = createobject("WScript.Shell").exec("mshta about:""<script>moveTo(-32000,-32000);</script><hta:application id=app border=dialog minimizebutton=no maximizebutton=no scroll=no showintaskbar=yes contextmenu=no selection=no innerborder=no /><object id='shellwindow' classid='clsid:8856F961-340A-11D0-A96B-00C04FD705A2'><param name=RegisterAsBrowser value=1></object><script>shellwindow.putproperty('" & signature & "',document.parentWindow);</script>""")
    do
        if proc.status > 0 then exit function
        for each shellwnd in createobject("Shell.Application").windows
            set createwindow = shellwnd.getproperty(signature)
            if err.number = 0 then exit function
            err.clear
        next
    loop
end function

答案 3 :(得分:0)

此脚本将显示循环期间所花费的循环数和变量值,并在循环完成后在1消息框中显示结果。

Dim RateOfChange, roc, watchvariable : roc = 1 : watchvariable = 1

for i=1 to 25
    watchvariable = (watchvariable * i) * 16
    RateOfChange = RateOfChange & "Iteration[" & roc & "]" & " - Value[" & watchvariable & "]" & vbcrlf
    roc = roc + 1
next

'NOTE uncomment this below to activate msgbox. 
'msgbox rateofchange
wscript.echo rateofchange