Home of Macro Scheduler - Macro Tools and Automation Software
Marcus’ Macro Blog
Mostly tips, tutorials, articles and news about Macro Scheduler & Windows Automation
Download Macro Scheduler
Free 30 Day Trial

Quoting Quotes

July 24th, 2008 by Marcus Tettmar

VBScript and Complex Expressions use the ” (double quote) character to delimit strings. Native MacroScript code doesn’t need delimited strings. But if you need to use Complex Expressions or VBScript you need to remember that strings must be delimited in quotes.

One implication of this is that if the string already has a ” character within it you will get a syntax error, because the parser thinks this marks the end of the string.

To avoid this you need to add another quote, and you can use StringReplace to replace any occurences of the ” character with a second one before passing the string to VBScript or a Complex Expression:

//example input string:
Let>mystring=your name is "Sally"

//Double quote before using string in complex expression
StringReplace>mystring,","",mystring_2
If>{%mystring_2% <> “”}
  //Do something
Endif

Without that StringReplace call to double quote the quote characters, the complex If line would produce a syntax error.

The same goes for VBScript:

//example input string:
Let>mystring=your name is "Sally"

VBSTART
VBEND

StringReplace>mystring,","",mystring_2
VBEval>MsgBox("%mystring_2%"),nul

Note that the VBEval statement evaluates a pure VBScript expression. Since VBScript strings must be in quotes we surround the variable mystring_2 with them, and need to use % symbols to tell Macro Scheduler to use the value of mystring_2. See my last post for tips on when and where to use % symbols.

On a similar note, CR LF pairs (Carriage Return and Line Feed) in strings passed to VBScript will produce errors since they are hard line breaks and cause string termination problems. We can avoid this by replacing the real CR and LF characters with the VBScript placeholders:

StringReplace>myString,CRLF," & vbCRLF & ",myString

The quotes terminate and start the string again, splitting it where the CRLF was, and replacing the hard CRLF with the VBScript vbCRLF variable. There’s also vbCR and vbLF variables for carriage returns (CR) and line feeds (LF) on their own.

Bookmark this at:
    Bookmark Quoting Quotes at del.icio.us    Digg Quoting Quotes at Digg.com    Bookmark Quoting Quotes at Spurl.net    Bookmark Quoting Quotes at Simpy.com    Bookmark Quoting Quotes at NewsVine    Blink this Quoting Quotes at blinklist.com    Bookmark Quoting Quotes at Furl.net    Bookmark Quoting Quotes at reddit.com    Fark Quoting Quotes at Fark.com    Bookmark Quoting Quotes at YahooMyWeb

Leave a Reply

Sitemap | Terms and Conditions | Privacy Policy | © MJT Net Ltd 1997-2008 All Rights Reserved.

Windows Vista and the Windows logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.