{"id":71643,"date":"2004-08-16T11:54:00","date_gmt":"2004-08-16T11:54:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2004\/08\/16\/how-can-i-give-a-user-a-yesno-prompt\/"},"modified":"2004-08-16T11:54:00","modified_gmt":"2004-08-16T11:54:00","slug":"how-can-i-give-a-user-a-yesno-prompt","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-give-a-user-a-yesno-prompt\/","title":{"rendered":"How Can I Give a User a Yes\/No Prompt?"},"content":{"rendered":"<p><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"><\/p>\n<p>Hey, Scripting Guy! I have a script which performs some file management tasks, and then should ask the user whether or not they want to delete a set of files. How do I ask a user a Yes or No question like this? <\/p>\n<p>&#8212; SE, Casper, WY<\/p>\n<p><img decoding=\"async\" border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><img decoding=\"async\" class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><a href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><img decoding=\"async\" class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/a><\/p>\n<p>Hey, SE. There are a couple different ways that you can do this, but because you\u2019re dealing with users the best way is probably to just pop up a message box and let them click Yes or No. How hard is <i>that<\/i>? Hey, it\u2019s no harder than these few lines of code:<\/p>\n<pre class=\"codeSample\">intAnswer = _\n    Msgbox(\"Do you want to delete these files?\", _\n        vbYesNo, \"Delete Files\")\nIf intAnswer = vbYes Then\n    Msgbox \"You answered yes.\"\nElse\n    Msgbox \"You answered no.\"\nEnd If\n<\/pre>\n<p>All we\u2019re doing here is creating a message box that features the following:<\/p>\n<table id=\"E5C\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<thead><\/thead>\n<tbody>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\"><b>The message to be displayed.<\/b><\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">In this example, the message is <i>Do you want to delete these files?<\/i><\/p>\n<\/td>\n<\/tr>\n<tr class=\"evenRecord\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\"><b>A Yes button and a No button.<\/b><\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">This is specified by the VBScript constant vbYesNo. There are other values that can give you different message box configurations; for example, you could have a message box with buttons labeled Abort, Retry, and Ignore. Who could forget good old Abort, Retry, and Ignore?<\/p>\n<\/td>\n<\/tr>\n<tr class=\"record\" vAlign=\"top\">\n<td>\n<p class=\"lastInCell\"><b>The message box caption.<\/b><\/p>\n<\/td>\n<td>\n<p class=\"lastInCell\">In this example, the caption is simply <i>Delete Files<\/i>.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<div class=\"dataTableBottomMargin\"><\/div>\n<p>The message box will sit there until the user clicks a button. And how do we know which button was clicked? Well, the results of the button click are stored in the variable intAnswer. All we have to do is check the value of intAnswer. If intAnswer is equal to another VBScript constant (vbYes) then we know the user must have clicked yes; if it\u2019s equal to anything else, then they must have clicked No. (After all, we only have two buttons, so if they didn\u2019t click Yes they <i>had<\/i> to have clicked No.)<\/p>\n<p>For more information about the MsgBox function, see the <a href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/script56\/html\/vsfctMsgBox.asp\" target=\"_blank\">VBScript documentation<\/a> on MSDN.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! I have a script which performs some file management tasks, and then should ask the user whether or not they want to delete a set of files. How do I ask a user a Yes or No question like this? &#8212; SE, Casper, WY Hey, SE. There are a couple different ways [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[15,3,4,5],"class_list":["post-71643","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-dialog-boxes","tag-scripting-guy","tag-scripting-techniques","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! I have a script which performs some file management tasks, and then should ask the user whether or not they want to delete a set of files. How do I ask a user a Yes or No question like this? &#8212; SE, Casper, WY Hey, SE. There are a couple different ways [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71643","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=71643"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/71643\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=71643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=71643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=71643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}