Q: How do you split VBScript into multiple lines?

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.

Please or Register to post comments.

IT/Dev Connections

Las Vegas
September 30th - October 4th

Paul ThurottYou'll have the opportunity to experience:
• The Microsoft
Technology Roadmap
• Office 365 Implementation
• Hyper-V Optimizing
• Windows 8 Deployment
and much more!

Come See Paul Thurrott & Rod Trent in Person!

Early Registration Now Open

Upcoming Training

Mastering System Center 2012

During over 6 hours of training you can join John Savill from your computer as he will walk you through the key components and capabilities of System Center 2012, what’s involved in using the components, and the benefit they can bring to your environment.

Register Now

Current Issue

May 2013 - The NameTranslate object is useful when you need to translate Active Directory object names between different formats, but it's awkward to use from PowerShell. Here's a PowerShell script that eliminates the awkwardness.

CURRENT ISSUE / ARCHIVE / SUBSCRIBE

Windows Forums

Get answers to questions, share tips, and engage with the Windows Community in our Forums.