{"id":88,"date":"2009-07-17T13:53:30","date_gmt":"2009-07-17T17:53:30","guid":{"rendered":"http:\/\/www.northatlantawebdesign.com\/?p=88"},"modified":"2009-07-27T10:05:59","modified_gmt":"2009-07-27T14:05:59","slug":"hta-progress-bar-using-vbscript-and-javascript","status":"publish","type":"post","link":"https:\/\/www.northatlantawebdesign.com\/index.php\/2009\/07\/17\/hta-progress-bar-using-vbscript-and-javascript\/","title":{"rendered":"HTA Progress Bar using VBScript and JavaScript"},"content":{"rendered":"<p>I was informed after my <a href=\"http:\/\/www.northatlantawebdesign.com\/index.php\/2009\/07\/16\/simple-vbscript-progress-bar\/\">last post<\/a> that using <a type=\"amzn\">HTA<\/a> (HTML Applications) to display a progress bar in <a type=\"amzn\">VBScript<\/a> is much more efficient than using InternetExplorer.Application within a VBScript.  Having never used HTA before, I immediately set out to learn a bit and see what I could come up with.<\/p>\n<p>My initial thoughts are mixed, as <strong>you can not run and interact with an HTA from a VBScript file<\/strong>.\u00a0 This requires you to wrap your VBScript code in whatever HTML Application you are writing.  This greatly limits re-usability, enough so that the increase in performance may not warrant using an HTA for a progress bar in most cases.<br \/>\n<!--more--><br \/>\nI would like to note that this is a first draft of this script, and I may update it in the future, if I deem HTML Applications the way to go.\u00a0 As for now, I am not convinced.<\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\r\n&lt;html&gt;\r\n&lt;head&gt;\r\n\t&lt;title&gt;HTA Progress Bar&lt;\/title&gt;\r\n&lt;script language=&quot;vbscript&quot;&gt;\r\n'This script resizes and moves the window to the center of the screen.\r\n'The placement of this code above the HTA definition, moves the window\r\n'before the script is visible. \r\nheight = screen.height\r\nwidth = screen.width\r\nmoveto width\/2 - 335\/2,height\/2 - 200\/2\r\nresizeto 335,200\r\n&lt;\/script&gt;\r\n\t&lt;HTA:APPLICATION ID=&quot;oMyApp&quot;\r\n\t\tAPPLICATIONNAME=&quot;monster&quot;\r\n\t\tSINGLEINSTANCE=&quot;yes&quot;\r\n\t\tBORDER=&quot;thin&quot;\r\n\t\tMAXIMIZEBUTTON=&quot;no&quot;\r\n&gt;\r\n\r\n&lt;script language=&quot;VBScript&quot; type=&quot;text\/vbscript&quot;&gt;\r\n'This is where your VBScript logic should go.\r\n' Call OpenProgressBar to open the progressbar\r\n' Call UpdateLog to update the logging window\r\n' Call UpdateProgressBar to move the bar\r\n' Call CloseProgressBar to return to your main UI window\r\nSub BeginImportingFiles()\r\n\tDim i\r\n\tOpenProgressBar()\r\n\tUpdateLog &quot;Step 1 of 2&quot;, &quot;&quot;\r\n\tFor i = 1 to 10\r\n\t\tSleep 100\r\n\t\tUpdateLog &quot;Next Step&quot;, &quot;&quot; &amp; Time()\r\n\t\tUpdateProgressBar i*10, &quot;Step 1 of 2&quot;\r\n\tNext\r\n\tUpdateLog &quot;Step 1 of 2&quot;, &quot;Complete&quot;\r\n\tSleep 2000\r\n\tCloseProgressBar()\r\nEnd Sub\r\n\r\nSub Sleep(MSecs) \r\n\tSet fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)\r\n\tIf Fso.FileExists(&quot;sleeper.vbs&quot;)=False Then\r\n\tSet objOutputFile = fso.CreateTextFile(&quot;sleeper.vbs&quot;, True)\r\n\tobjOutputFile.Write &quot;wscript.sleep WScript.Arguments(0)&quot;\r\n\tobjOutputFile.Close\r\n\tEnd If\r\n\tCreateObject(&quot;WScript.Shell&quot;).Run &quot;sleeper.vbs &quot; &amp; MSecs,1 , True\r\nEnd Sub\r\n\r\n&lt;\/script&gt;\r\n&lt;script language=&quot;JavaScript&quot; type=&quot;text\/javascript&quot;&gt;\r\nfunction OpenProgressBar()\r\n{\r\n\tdocument.getElementById(&quot;gui&quot;).style.display=&quot;none&quot;;\r\n\tdocument.getElementById(&quot;progressbargui&quot;).style.display=&quot;block&quot;;\r\n}\r\n\r\nfunction UpdateLog(text, status)\r\n{\r\n\tvar log = document.getElementById(&quot;log&quot;);\r\n\tif(status &amp;&amp; status != &quot;&quot;)\r\n\t{\r\n\t\tvar maxLength = 33;\r\n\t\tvar dotlength = maxLength - (text.length + status.length);\r\n\t\tvar dots = &quot;&quot;;\r\n\t\tfor(i = 0;i&lt;dotlength;i++)\r\n\t\t\tdots += &quot;.&quot;;\r\n\t\tlog.value += text + dots + &quot;&#x5B;&quot; + status + &quot;]\\n&quot;;\r\n\t}\r\n\telse\r\n\t\tlog.value += &quot;&#x5B;&quot; + text + &quot;]&quot; + &quot;\\n&quot;;\r\n\tlog.scrollTop = log.scrollHeight;\r\n}\r\n\r\nfunction UpdateProgressBar(percentComplete, title, status)\r\n{\r\n\tfor(i = 1; i &lt;= 100; i++)\r\n\t{\r\n\t\tif((percentComplete) &gt;= i)\r\n\t\t\tdocument.getElementById(&quot;pbar&quot;+i).className = &quot;pbarcomplete&quot;;\r\n\t\telse\r\n\t\t\tdocument.getElementById(&quot;pbar&quot;+i).className = &quot;pbar&quot;;\r\n\t\tdocument.title = title &amp;&amp; title != &quot;&quot; ? title : percentComplete + &quot;% Complete&quot;;\r\n\t\tdocument.getElementById(&quot;progresstitle&quot;).innerText = status &amp;&amp; status != &quot;&quot; ? status : percentComplete + &quot;% Complete&quot;;\r\n\t}\r\n}\r\n\r\nfunction CloseProgressBar()\r\n{\r\n\tdocument.getElementById(&quot;gui&quot;).style.display=&quot;block&quot;;\r\n\tdocument.getElementById(&quot;progressbargui&quot;).style.display=&quot;none&quot;;\r\n\tUpdateProgressBar(0,&quot;&quot;,&quot;&quot;);\r\n\tdocument.getElementById(&quot;log&quot;).value = &quot;&quot;;\r\n}\r\n&lt;\/script&gt;\r\n&lt;script language=&quot;VBScript&quot; type=&quot;text\/vbscript&quot;&gt;\r\n'Progress Bar Logic\r\n&lt;\/script&gt;\r\n&lt;style type=&quot;text\/css&quot;&gt;\r\nbody,html {\r\n\tmargin:auto;\r\n}\r\ndiv#progressbar{\r\nborder:1px solid #ccc;\r\nmargin:0px;padding:0px;\r\n}\r\nspan.pbar{\r\n\twidth:3px;\r\n\tmargin:0px;\r\n\tpadding:0px;\r\n\tborder-left:1px solid #fff;\r\n\tbackground:#fff;\r\n\tline-height:5px;\r\n\theight:16px;\r\n\tfont-size:2px;\r\n}\r\nspan.pbarcomplete{\r\n\twidth:3px;\r\n\tmargin:0px;\r\n\tpadding:0px;\r\n\tborder-right:1px solid #ccc;\r\n\tbackground:green;\r\n\tline-height:5px;\r\n\theight:16px;\r\n\tfont-size:2px;\r\n\t\r\n}\r\ntable {\r\n\twidth:100%;\r\n\theight:100%;\r\n}\r\ntable td {\r\n\ttext-align:center;\r\n\tvertical-align:center;\r\n}\r\ntable td.progressbargui {\r\n\tdisplay:none;\r\n\tvertical-align:top;\r\n}\r\ntextarea#log{\r\n\twidth:100%;\r\n\theight:100px;\r\n\tborder:1px solid #aaa;\r\n}\r\n&lt;\/style&gt;\r\n&lt;\/head&gt;\r\n&lt;body&gt;\r\n&lt;table&gt;\r\n&lt;tr&gt;\r\n\t&lt;td id=&quot;gui&quot;&gt;&lt;input type=&quot;button&quot; onclick=&quot;BeginImportingFiles()&quot; value=&quot;Begin File Import&quot;\/&gt;&lt;\/td&gt;\r\n\t&lt;td id=&quot;progressbargui&quot; class=&quot;progressbargui&quot;&gt;\r\n\t\t&lt;div id=&quot;progresstitle&quot;&gt;&amp;nbsp;&lt;\/div&gt;\r\n\t\t&lt;div id=&quot;progressbar&quot;&gt;\r\n\t\t&lt;script type=&quot;text\/javascript&quot;&gt;\r\n\t\tfor(i = 1; i &lt;= 100; i++)\r\n\t\t\tdocument.write(&quot;&lt;span id=\\&quot;pbar&quot; + i + &quot;\\&quot; class=\\&quot;pbar\\&quot;&gt;&lt;\/span&gt;&quot;);\r\n\t\t&lt;\/script&gt;\r\n\t\t&lt;\/div&gt;\r\n\t\t&lt;textarea id=&quot;log&quot;&gt;&lt;\/textarea&gt;\r\n\t&lt;\/td&gt;\r\n&lt;\/tr&gt;\r\n&lt;\/table&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n\r\n<\/pre>\n<p>Some potentially useful links dealing with HTA:<\/p>\n<ul>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms536496%28VS.85%29.aspx\" target=\"_blank\">HTML Applications Introduction<\/a><\/li>\n<li><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms536473%28VS.85%29.aspx\" target=\"_blank\">HTA Reference<\/a><\/li>\n<li><a href=\"http:\/\/www.amazon.com\/gp\/product\/0735622442?ie=UTF8&#038;tag=cheesymovieni-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0735622442\" target=\"_blank\">Advanced VBScript for Microsoft  Windows  Administrators (Book)<\/a><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.assoc-amazon.com\/e\/ir?t=cheesymovieni-20&#038;l=as2&#038;o=1&#038;a=0735622442\" width=\"1\" height=\"1\" border=\"0\" alt=\"\" style=\"border:none !important; margin:0px !important;\" \/>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I was informed after my last post that using HTA (HTML Applications) to display a progress bar in VBScript is much more efficient than using InternetExplorer.Application within a VBScript. Having never used HTA before, I immediately set out to learn a bit and see what I could come up with. My initial thoughts are mixed, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[27,28,23],"tags":[29,77,78,24,30,75,31,32],"class_list":["post-88","post","type-post","status-publish","format-standard","hentry","category-html-applications","category-javascript","category-vbscript","tag-hta","tag-html-applications","tag-javascript","tag-progress-bar","tag-progressbar","tag-vbscript","tag-vbscript-front-end","tag-vbscript-gui"],"_links":{"self":[{"href":"https:\/\/www.northatlantawebdesign.com\/index.php\/wp-json\/wp\/v2\/posts\/88","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=88"}],"version-history":[{"count":20,"href":"https:\/\/www.northatlantawebdesign.com\/index.php\/wp-json\/wp\/v2\/posts\/88\/revisions"}],"predecessor-version":[{"id":131,"href":"https:\/\/www.northatlantawebdesign.com\/index.php\/wp-json\/wp\/v2\/posts\/88\/revisions\/131"}],"wp:attachment":[{"href":"https:\/\/www.northatlantawebdesign.com\/index.php\/wp-json\/wp\/v2\/media?parent=88"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.northatlantawebdesign.com\/index.php\/wp-json\/wp\/v2\/categories?post=88"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.northatlantawebdesign.com\/index.php\/wp-json\/wp\/v2\/tags?post=88"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}