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.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish