How Can I Display More Than 1,023 Characters in a Custom Message Box?

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’t change the message box title. I can change the title of a message box used by the VBscript MsgBox function, but it won’t hold all my characters. Can you help?

-- KB

Hey, KB. Talk about a no-win situation. As you’ve discovered, the VBScript MsgBox 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 Wscript.Echo method, by contrast, can display more than 1,023 characters. That’s 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 always be titled Windows Script Host.

Incidentally, if you want to see what we’re talking about, try running this little test script. The test script creates a string consisting of 1,023 periods followed by the letter X. (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.

Note. 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.

Take a look at the message box that appears when we use the MsgBox function; notice that the X (character number 1,024) doesn’t show up. You might note as well that this message box doesn’t even have a title; that’s because we didn’t give it one:

Now here’s the same message displayed using Wscript.Echo. Notice that this time the X (character number 1,024) is displayed; unfortunately, though, we’re stuck with the message box title Windows Script Host:

So what’s the answer to our dilemma? As it turns out, the answer is to use the Windows Script Host Popup method. Popup can display as many characters as Wscript.Echo plus it allows us to specify a custom title for our message box. It’s the best of both worlds.

Let’s show you a sample script that uses the Popup method, and then we’ll explain how it works:

We begin by defining a pair of constants - OK_BUTTON and AUTO_DISMISS - and set the value of each of these constants to 0. Later on in the script we’ll use OK_BUTTON to indicate that we want a message box that uses only an OK button, and we’ll use AUTO_DISMISS to indicate that we want the message box to remain onscreen until the user clicks OK. Does that mean we could create message boxes that use buttons other than just OK, and that we could create message boxes that can automatically dismiss themselves? You bet it does; for more information, see the Windows Script Host documentation on MSDN.

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 X: