{"id":69683,"date":"2005-06-02T15:23:00","date_gmt":"2005-06-02T15:23:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/06\/02\/how-can-i-display-more-than-1023-characters-in-a-custom-message-box\/"},"modified":"2005-06-02T15:23:00","modified_gmt":"2005-06-02T15:23:00","slug":"how-can-i-display-more-than-1023-characters-in-a-custom-message-box","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-display-more-than-1023-characters-in-a-custom-message-box\/","title":{"rendered":"How Can I Display More Than 1,023 Characters in a Custom Message Box?"},"content":{"rendered":"<p><IMG 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\"> \n<P>Hey, Scripting Guy! I need to create a custom alert box that has over 1,000 characters in it. The message box used by Wscript.Echo can hold all the characters, but I can\u2019t change the message box title. I can change the title of a message box used by the VBscript MsgBox function, but it won\u2019t hold all my characters. Can you help?<BR><BR>&#8212; KB<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG 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 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> \n<P>Hey, KB. Talk about a no-win situation. As you\u2019ve discovered, the VBScript <B>MsgBox<\/B> function can display a maximum of 1,023 characters; if you have a string larger than that, any characters past the first 1,023 will be cut off. The <B>Wscript.Echo<\/B> method, by contrast, <I>can<\/I> display more than 1,023 characters. That\u2019s great, except for one thing: with MsgBox you can change the title of the actual message box, but with Wscript.Echo your message box will <I>always<\/I> be titled <B>Windows Script Host<\/B>. <\/P>\n<P>Incidentally, if you want to see what we\u2019re talking about, try running this little test script. The test script creates a string consisting of 1,023 periods followed by the letter <I>X<\/I>. (In other words, a message that makes absolutely no sense, which puts it on a par with most of these columns.) We then display the message box using both the MsgBox function and the Wscript.Echo method.<\/P>\n<TABLE id=\"END\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B>. Of course, Wscript.Echo displays a message box only when the script is run under Wscript; otherwise the message will be written to a command window.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Here\u2019s the test script:<\/P><PRE class=\"codeSample\">Set objShell = CreateObject(&#8220;Wscript.Shell&#8221;)\nFor i = 1 to 1023\n   strMessage = strMessage &amp; &#8220;.&#8221;\nNext\nstrMessage = strMessage &amp; &#8220;X&#8221;<\/p>\n<p>MsgBox strMessage\nWscript.Echo strMessage\n<\/PRE>\n<P>Take a look at the message box that appears when we use the MsgBox function; notice that the <I>X<\/I> (character number 1,024) doesn\u2019t show up. You might note as well that this message box doesn\u2019t even <I>have<\/I> a title; that\u2019s because we didn\u2019t give it one:<\/P><IMG border=\"0\" alt=\"Message Box\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/popupa.jpg\" width=\"375\" height=\"108\"> \n<P><BR>Now here\u2019s the same message displayed using Wscript.Echo. Notice that this time the <I>X<\/I> (character number 1,024) is displayed; unfortunately, though, we\u2019re stuck with the message box title <B>Windows Script Host<\/B>:<\/P><IMG border=\"0\" alt=\"Message Box\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/popupb.jpg\" width=\"375\" height=\"108\"> \n<P><BR>So what\u2019s the answer to our dilemma? As it turns out, the answer is to use the Windows Script Host <B>Popup<\/B> method. Popup can display as many characters as Wscript.Echo <I>plus<\/I> it allows us to specify a custom title for our message box. It\u2019s the best of both worlds.<\/P>\n<P>Let\u2019s show you a sample script that uses the Popup method, and then we\u2019ll explain how it works:<\/P><PRE class=\"codeSample\">Const OK_BUTTON = 0\nConst AUTO_DISMISS = 0<\/p>\n<p>Set objShell = CreateObject(&#8220;Wscript.Shell&#8221;)<\/p>\n<p>For i = 1 to 1023\n   strMessage = strMessage &amp; &#8220;.&#8221;\nNext\nstrMessage = strMessage &amp; &#8220;X&#8221;<\/p>\n<p>objShell.Popup strMessage, AUTO_DISMISS, &#8220;My Message Box&#8221;, OK_BUTTON\n<\/PRE>\n<P>We begin by defining a pair of constants &#8211; OK_BUTTON and AUTO_DISMISS &#8211; and set the value of each of these constants to 0. Later on in the script we\u2019ll use OK_BUTTON to indicate that we want a message box that uses only an <B>OK<\/B> button, and we\u2019ll use AUTO_DISMISS to indicate that we want the message box to remain onscreen until the user clicks <B>OK<\/B>. Does that mean we could create message boxes that use buttons other than just <B>OK<\/B>, and that we could create message boxes that can automatically dismiss themselves? You bet it does; for more information, see the <A href=\"http:\/\/msdn.microsoft.com\/library\/en-us\/script56\/html\/wsMthPopup.asp\" target=\"_blank\"><B>Windows Script Host<\/B><\/A> documentation on MSDN.<\/P>\n<P>Next we create an instance of the WSH Shell object, the object that actually contains the Popup method. We then use these lines of code to create our string of 1,023 periods plus the letter <I>X<\/I>:<\/P><PRE class=\"codeSample\">For i = 1 to 1023\n   strMessage = strMessage &amp; &#8220;.&#8221;\nNext\nstrMessage = strMessage &amp; &#8220;X&#8221;\n<\/PRE>\n<P>All that\u2019s left now is to call the Popup method and display a message box containing our entire string, a message box that also has the custom title <B>My Message Box<\/B>:<\/P><PRE class=\"codeSample\">objShell.Popup strMessage, AUTO_DISMISS, &#8220;My Message Box&#8221;, OK_BUTTON\n<\/PRE>\n<P>As you can see, the Popup method takes four parameters:<\/P>\n<TABLE border=\"0\" cellSpacing=\"0\" cellPadding=\"0\">\n<TBODY>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P><I>strMessage<\/I>, the text we want to display.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P><I>AUTO_DISMISS<\/I>, the constant that tells Popup to keep the message box displayed until the user clicks <B>OK<\/B>.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P><I>\u201cMy Message Box\u201d<\/I>, the custom title for the message box.<\/P><\/TD><\/TR>\n<TR>\n<TD class=\"listBullet\" vAlign=\"top\">\u2022<\/TD>\n<TD class=\"listItem\">\n<P><I>OK_BUTTON<\/I>, the constant that tells Popup to include only an <B>OK<\/B> button in the message box.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<P>When we run the script we should see a message box that not only displays all 1,024 characters, but has a custom title as well:<\/P><IMG border=\"0\" alt=\"Message Box\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/qanda\/popupc.jpg\" width=\"375\" height=\"108\"> \n<P><BR>Just what the doctor ordered.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! I need to create a custom alert box that has over 1,000 characters in it. The message box used by Wscript.Echo can hold all the characters, but I can\u2019t change the message box title. I can change the title of a message box used by the VBscript MsgBox function, but it won\u2019t [&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,714],"class_list":["post-69683","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-dialog-boxes","tag-scripting-guy","tag-scripting-techniques","tag-vbscript","tag-wshshell"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! I need to create a custom alert box that has over 1,000 characters in it. The message box used by Wscript.Echo can hold all the characters, but I can\u2019t change the message box title. I can change the title of a message box used by the VBscript MsgBox function, but it won\u2019t [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69683","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=69683"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/69683\/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=69683"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=69683"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=69683"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}