MSGbox in VBS, which updates the value of a variable

It's just interesting how I can have an MSgbox that displays the value of a variable as it is constantly changing. Basically a number is added to it every time it loops. I want to show that in MSGbox, which should not open a million windows

+3
vbscript
source share
4 answers

A workaround would be to use PopUp

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

This will "autocline" the MsgBox for 1 second

+5
source share

You cannot do this with the default VBScript dialog elements like MsgBox , WScript.Echo or Popup . You need to create a custom dialog using the Internet Explorer COM object:

 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 

or use HTA instead of regular 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
source share

Another solution, using an HTA window without temporary files:

 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 
+2
source share

This script will display how many cycles it took and the value of the variable during the cycle, and display the results in 1 message box after the cycle ends.

 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 
0
source share

All Articles