Q: How do you split VBScript into multiple lines?

VBScript linebreaks demystified.

John Savill

October 24, 2011

1 Min Read
ITPro Today logo in a gray background | ITPro Today

A: You might have a very long VBScript statement that’s hard to read, so you need to split it over multiple lines.

For example, look at the following VBScript:

Do While ( ( (intHB <> 2) And (intTimer <= arrStartMaxTime(counter)) And (Not arrAlwaysWaitStartMaxTime(counter)) ) Or  ( (intTimer <= arrStartMaxTime(counter)) And arrAlwaysWaitStartMaxTime(counter) ) Or ( (intHB = 2) And (intTimer < (arrTimeForHBDetect(counter)+arrExtraStartWait(counter))) ))

Splitting this over multiple lines would be preferred.

The good news is, it’s easy: Just add an underscore at the end of a line to continue it to the next line. Here’s an example:

Do While ( ( (intHB <> 2) And (intTimer <= arrStartMaxTime(counter)) And (Not arrAlwaysWaitStartMaxTime(counter)) ) _
                                Or _
                                ( (intTimer <= arrStartMaxTime(counter)) And arrAlwaysWaitStartMaxTime(counter) ) _    
                                Or _
                                ( (intHB = 2) And (intTimer < (arrTimeForHBDetect(counter)+arrExtraStartWait(counter))) ) _ 
                                )

What’s important to note is that you can’t add comments at the end of the lines that have an underscore, because the comment would be placed in the middle of the command.

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like