{"id":16,"date":"2006-12-15T06:34:06","date_gmt":"2006-12-15T14:34:06","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2006\/12\/15\/order-up\/"},"modified":"2006-12-15T06:34:06","modified_gmt":"2006-12-15T14:34:06","slug":"order-up","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2006\/12\/15\/order-up\/","title":{"rendered":"Order up!"},"content":{"rendered":"<p>A recurring question I&#8217;ve seen over the years in a number of VBScript forums is how to present a menu dialog in a script. Other than InputBox, MsgBox or the WshShell&#8217;s Popup Method, there aren&#8217;t too many GUI alternatives.&nbsp; And none of them (at least at first glance) looks like it could be used to present a menu. Now, if you want to got all out with fancy formatting and buttons, then you should look to creating an HTA or use an instance of Internet Explorer.&nbsp; But if your needs are simple, I can show you how to accomplish this with a simple InputBox.<\/p>\n<p>Here&#8217;s a script sample of how you might accomplish this.&nbsp; I&#8217;ve also attached the script as text file for your convenience. (There really is a file attached.&nbsp; It&#8217;s just less than 1KB)<\/p>\n<p><span style=\"font-family: Courier New,Courier,mono;\">&#8216;MyMenu.vbs<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">strTitle=&#8221;My Menu&#8221;<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">strErrMsg=&#8221;Invalid option! You must choose a number between 1 and 5.&#8221;<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">strMenu=&#8221;Please select an option:&#8221; &amp; VbCrLf &amp;_<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;1 Kung Pao Shrimp&#8221; &amp; VbCrLf &amp;_<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;2 Sweet and Sour Chicken&#8221; &amp; VbCrLf &amp;_<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;3 Mongolian Been&#8221; &amp; VbCrLf &amp;_<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;4 Pan Fried Dumplings&#8221; &amp; VbCrLf &amp;_<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#8220;5 Stir Fry Surprise&#8221;<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">rc=InputBox(strMenu,strTitle,&#8221;0&#8243;)<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">If rc=&#8221;&#8221; Then WScript.quit<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">If IsNumeric(rc) Then<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp; Select Case (rc)<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case 1<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WScript.Echo &#8220;One order of Kung Pao Shrimp!&#8221;<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case 2<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WScript.Echo &#8220;Would you like rice with your chicken?&#8221;<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case 3<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WScript.Echo &#8220;How spicy would you like the Mongolian Beef?&#8221;<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case 4<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WScript.Echo &#8220;How many dumplings?&#8221;<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case 5<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WScript.Echo &#8220;You are definitely in for a surprise.&#8221;<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case Else <\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WScript.Echo strErrMsg<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; WScript.quit<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp; End Select<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">Else<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">&nbsp;&nbsp;&nbsp; WScript.Echo strErrMsg<\/span><br style=\"font-family: Courier New,Courier,mono;\"><span style=\"font-family: Courier New,Courier,mono;\">End If<\/span><\/p>\n<p>The only real &#8220;trick&#8221; to this script is properly formatting a message for the input box. You don&#8217;t have unlimited space so you need to design something simple and to the point. If you can use numbers as menu choices as I&#8217;ve done, here it makes life a little easier. Because I&#8217;m expecting a numeric value, I can test for it and handle errors such as when someone isn&#8217;t paying attention and types in a word.&nbsp; (I&#8217;ve also used some error handling in case the return value is blank in which case the user either clicked Cancel or tried to enter a blank value.)<\/p>\n<p>Once I know the user entered a numeric value, I can use a Select Case statement to decide what to do based on the menu number they entered.&nbsp; When you run the script, you&#8217;ll see a dialog box like this:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/sapien.eponym.com\/screenshots\/mymenu.png\"><\/p>\n<p>I gave the InputBox a default value of 0 to give the user the idea that they need to enter a number. There is error handling in the Select Case statement if the user clicks OK with a value of 0. You may prefer to set the default value to a menu choice.<\/p>\n<p>So the next time you need to take an order in your script, an InputBox may be all that you need.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A recurring question I&#8217;ve seen over the years in a number of VBScript forums is how to present a menu dialog in a script. Other than InputBox, MsgBox or the WshShell&#8217;s Popup Method, there aren&#8217;t too many GUI alternatives.  And none of them (at least at first glance) looks like it could be used to present a menu. Now, if you want to got all out with fancy formatting and buttons, then you should look to creating an HTA or use an instance of Internet Explorer.  But if your needs are simple, I can show you how to accomplish this with a simple InputBox.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2,24],"tags":[],"class_list":["post-16","post","type-post","status-publish","format-standard","hentry","category-general","category-vbscript"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/16","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=16"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/16\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=16"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=16"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=16"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}