Powered by: newtelligence dasBlog 1.8.5223.1
Wednesday, March 30, 2005
I've run into this often: the need to have a VBScript constant containing a line-break character. Today I finally got a definitive answer on whether it's possible (for the impatient, the answer is NO).
If you're interested in history...
Of course this is right out:
CONST blah = "hello there"
The normal approach I've tried was this:
CONST blah = "hello " & vbCRLF & " there"
Now in JScript/Javascript/ECMAScript, you can do this:
var blah = "hello \r\n there"
Unfortunately, there's no similar switch in VBScript. While HTML does honor ASCII codes like or , and web browsers honor hexadecimal codes in URLs, VBScript does neither. So these also don't work:
CONST blah ="hello there" CONST blah = "hello %0A%0D there" CONST blah = "hello 0x0A0x0D there"
So I was reading a blog entry by Eric Lippert (who I believe wrote most of VBScript) today, and he mentioned Constant Folding, and proceeded to outline the mechanics behind this VBScript constant problem. It rung a bell, I asked about line-breaks in VBScript constants in his comments, and Eric responded: "Sorry, you are correct -- there's no way to do that. Sub-optimal, I know. " ...Straight from the dev's mouth.
SO, if you need a line-break in a VBScript constant, just use a variable instead:
DIM blah blah = "hello " & vbCRLF & " there"
Remember Me