{"id":69,"date":"2009-07-16T13:26:17","date_gmt":"2009-07-16T17:26:17","guid":{"rendered":"http:\/\/www.northatlantawebdesign.com\/?p=69"},"modified":"2009-07-27T10:08:01","modified_gmt":"2009-07-27T14:08:01","slug":"simple-vbscript-progress-bar","status":"publish","type":"post","link":"https:\/\/www.northatlantawebdesign.com\/index.php\/2009\/07\/16\/simple-vbscript-progress-bar\/","title":{"rendered":"Simple VBScript Progress Bar"},"content":{"rendered":"<p>Recently I had a need for a simple progress bar written in <a type=\"amzn\">VBScript<\/a> to let users know what was going on in a multi-step application.  To my surprise, VBScript has nothing built in for a progress bar.\u00a0 After much searching, I was able to find <a title=\"Copy Files with Progress Bar\" href=\"http:\/\/www.tek-tips.com\/viewthread.cfm?qid=1196550&amp;page=1\">this thread<\/a> that linked to yet <a title=\"Adding some kind of progress\" href=\"http:\/\/www.tek-tips.com\/viewthread.cfm?qid=898604\">another thread<\/a> with a simple progress bar done in HTML using InternetExplorer.Application.\u00a0 I have taken this code and modified it to show an actual progess bar, with percentages, that can be updated as desired.\u00a0 I&#8217;ve wrapped it up in a nice easy-to-use class for reusability.\u00a0 Enjoy!<\/p>\n<p><!--more--><\/p>\n<div id=\"attachment_82\" style=\"width: 322px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-82\" class=\"size-full wp-image-82\" title=\"Simple VBScript Progress Bar\" src=\"http:\/\/www.northatlantawebdesign.com\/wp-content\/uploads\/2009\/07\/vbscript_progress_bar.gif\" alt=\"Simple VBScript Progress Bar\" width=\"312\" height=\"99\" srcset=\"https:\/\/www.northatlantawebdesign.com\/wp-content\/uploads\/2009\/07\/vbscript_progress_bar.gif 312w, https:\/\/www.northatlantawebdesign.com\/wp-content\/uploads\/2009\/07\/vbscript_progress_bar-300x95.gif 300w\" sizes=\"auto, (max-width: 312px) 100vw, 312px\" \/><p id=\"caption-attachment-82\" class=\"wp-caption-text\">Simple VBScript Progress Bar<\/p><\/div>\n<p>VBScript Progress Bar Class:<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\nClass ProgressBar\r\nPrivate m_PercentComplete\r\nPrivate m_CurrentStep\r\nPrivate m_ProgressBar\r\nPrivate m_Title\r\nPrivate m_Text\r\nPrivate m_StatusBarText\r\n\r\n'Initialize defaults\r\nPrivate Sub ProgessBar_Initialize\r\nm_PercentComplete = 0\r\nm_CurrentStep = 0\r\nm_Title = &quot;Progress&quot;\r\nm_Text = &quot;&quot;\r\nEnd Sub\r\n\r\nPublic Function SetTitle(pTitle)\r\nm_Title = pTitle\r\nEnd Function\r\n\r\nPublic Function SetText(pText)\r\nm_Text = pText\r\nEnd Function\r\n\r\nPublic Function Update(percentComplete)\r\nm_PercentComplete = percentComplete\r\nUpdateProgressBar()\r\nEnd Function\r\n\r\nPublic Function Show()\r\nSet m_ProgressBar = CreateObject(&quot;InternetExplorer.Application&quot;)\r\n'in code, the colon acts as a line feed\r\nm_ProgressBar.navigate2 &quot;about:blank&quot; : m_ProgressBar.width = 315 : m_ProgressBar.height = 40 : m_ProgressBar.toolbar = false : m_ProgressBar.menubar = false : m_ProgressBar.statusbar = false : m_ProgressBar.visible = True\r\nm_ProgressBar.document.write &quot;&lt;body Scroll=no style='margin:0px;padding:0px;'&gt;&lt;div style='text-align:center;'&gt;&lt;span name='pc' id='pc'&gt;0&lt;\/span&gt;&lt;\/div&gt;&quot;\r\nm_ProgressBar.document.write &quot;&lt;div id='statusbar' name='statusbar' style='border:1px solid blue;line-height:10px;height:10px;color:blue;'&gt;&lt;\/div&gt;&quot;\r\nm_ProgressBar.document.write &quot;&lt;div style='text-align:center'&gt;&lt;span id='text' name='text'&gt;&lt;\/span&gt;&lt;\/div&gt;&quot;\r\nEnd Function\r\n\r\nPublic Function Close()\r\nm_ProgressBar.quit\r\nm_ProgressBar = Nothing\r\nEnd Function\r\n\r\nPrivate Function UpdateProgressBar()\r\nIf m_PercentComplete = 0 Then\r\nm_StatusBarText = &quot;&quot;\r\nEnd If\r\nFor n = m_CurrentStep to m_PercentComplete - 1\r\nm_StatusBarText = m_StatusBarText &amp; &quot;|&quot;\r\nm_ProgressBar.Document.GetElementById(&quot;statusbar&quot;).InnerHtml = m_StatusBarText\r\nm_ProgressBar.Document.title = n &amp; &quot;% Complete : &quot; &amp; m_Title\r\nm_ProgressBar.Document.GetElementById(&quot;pc&quot;).InnerHtml = n &amp; &quot;% Complete : &quot; &amp; m_Title\r\nwscript.sleep 10\r\nNext\r\nm_ProgressBar.Document.GetElementById(&quot;statusbar&quot;).InnerHtml = m_StatusBarText\r\nm_ProgressBar.Document.title = m_PercentComplete &amp; &quot;% Complete : &quot; &amp; m_Title\r\nm_ProgressBar.Document.GetElementById(&quot;pc&quot;).InnerHtml = m_PercentComplete &amp; &quot;% Complete : &quot; &amp; m_Title\r\nm_ProgressBar.Document.GetElementById(&quot;text&quot;).InnerHtml = m_Text\r\nm_CurrentStep = m_PercentComplete\r\nEnd Function\r\n\r\nEnd Class\r\n<\/pre>\n<p>Example of Usage:<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n'Declare progressbar and percentage complete\r\nDim pb\r\nDim percentComplete\r\n'Setup the initial progress bar\r\nSet pb = New ProgressBar\r\npercentComplete = 0\r\npb.SetTitle(&quot;Step 1 of 5&quot;)\r\npb.SetText(&quot;Copying bin\/Debug Folder&quot;)\r\npb.Show()\r\n\r\n'Loop to update the percent complete of the progress bar\r\n'Just add the pb.Update in your code to update the bar\r\n'Text can be updated as well by pb.SetText\r\nDo While percentComplete &lt;= 100\r\nwscript.sleep 500\r\npb.Update(percentComplete)\r\npercentComplete = percentComplete + 10\r\nLoop\r\nwscript.sleep 3000\r\n\r\n'This shows how you can use the code for multiple steps\r\n'In a future iteration I will add a second bar to measure overall progress\r\npercentComplete = 0\r\npb.SetTitle(&quot;Step 2 of 5&quot;)\r\npb.SetText(&quot;Copying bin\/Release Folder&quot;)\r\npb.Update(percentComplete)\r\nDo While percentComplete &lt;= 100\r\nwscript.sleep 500\r\npb.Update(percentComplete)\r\npercentComplete = percentComplete + 10\r\nLoop\r\npb.Close()\r\nwscript.quit\r\n<\/pre>\n<p>In a future release, I may add another progress bar to keep track of the steps that are completed.  Feel free to use and modify this code as you desire.<\/p>\n<p>Useful Links:<\/p>\n<ul>\n<li><a title=\"Microsoft VBScript Reference\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/d1wf56tt%28VS.85%29.aspx\">Microsoft VBScript Reference<\/a><\/li>\n<li><a title=\"W3Schools VBScript Reference\" href=\"http:\/\/www.w3schools.com\/Vbscript\/default.asp\">W3Schools VBScript Reference<\/a><\/li>\n<li><a title=\"Copy Files with a Progress Bar\" href=\"http:\/\/www.tek-tips.com\/viewthread.cfm?qid=1196550&amp;page=1\">Copy Files with a Progress Bar<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Recently I had a need for a simple progress bar written in VBScript to let users know what was going on in a multi-step application. To my surprise, VBScript has nothing built in for a progress bar.\u00a0 After much searching, I was able to find this thread that linked to yet another thread with a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[26,76,24,75],"class_list":["post-69","post","type-post","status-publish","format-standard","hentry","category-vbscript","tag-class","tag-internet-explorer","tag-progress-bar","tag-vbscript"],"_links":{"self":[{"href":"https:\/\/www.northatlantawebdesign.com\/index.php\/wp-json\/wp\/v2\/posts\/69","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.northatlantawebdesign.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.northatlantawebdesign.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.northatlantawebdesign.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.northatlantawebdesign.com\/index.php\/wp-json\/wp\/v2\/comments?post=69"}],"version-history":[{"count":18,"href":"https:\/\/www.northatlantawebdesign.com\/index.php\/wp-json\/wp\/v2\/posts\/69\/revisions"}],"predecessor-version":[{"id":132,"href":"https:\/\/www.northatlantawebdesign.com\/index.php\/wp-json\/wp\/v2\/posts\/69\/revisions\/132"}],"wp:attachment":[{"href":"https:\/\/www.northatlantawebdesign.com\/index.php\/wp-json\/wp\/v2\/media?parent=69"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.northatlantawebdesign.com\/index.php\/wp-json\/wp\/v2\/categories?post=69"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.northatlantawebdesign.com\/index.php\/wp-json\/wp\/v2\/tags?post=69"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}