VBScript and Getting the Message Across

In preparing a post today I’ve been through a bit of a winding process whereby I came across an issue I’d never encountered before with a VBScript.  At first I thought I’d made some sort of mistake, but it appears I’d come across a limitation of a VBScript function I use all the time - MsgBox.

Obviously the information is available in the VBScript documentation, but it seems rather vague:

The maximum length of prompt is approximately 1,024 characters, depending on the width of the characters used.

My tests have shown that it always seems to truncate at the 1,023rd character.

So what’s the alternative?  Well there are two WSH options.  The first is WScript.Echo which seems to have a huge limit of what it can display.  So much so that in testing I more than completely and successfully filled my screen with 92,160 characters using this function.  The second is more aligned to MsgBox and is the WshShell.PopUp method which has similar options to VBScript’s message box.

An example script illustrating these options is given below.

Option Explicit

'Initialise
Dim strChunk
Dim strOut
Dim objWshShell
Dim intCount

Set objWshShell = WScript.CreateObject("WScript.Shell")
strChunk = ""
strOut = ""

'Build a chunk
For intCount = 1 to 1023
    strChunk = strChunk & "."
Next

'Add a number to the end of a chunk and join 9 chunks together
For intCount = 1 to 9
    strOut = strOut & strChunk & intCount
Next

'Display the total output in a message box
MsgBox strOut, vbInformation + vbOKOnly, "Message Box"

'Display the total output in a script echo
WScript.echo strOut

'Display the total output in a shell pop up
objWshShell.Popup strOut, 0, "Shell Popup", vbInformation
Author: Stephen Millard
Tags: | vbs |

Buy me a coffeeBuy me a coffee



Related posts that you may also like to read