Thursday, July 02, 2009

[VB6] Using VBScript's Escape and UnEscape

Something again from an answer I gave on StackOverflow. This one demonstrates how to use MSScriptControl.ScriptControl to make VBScript's Escape and Unescape functions available to the VB6 programmer.

The best thing would be add MSSCRIPT.OCX to the project, but for the sake of demonstration, I'll use CreateObject instead.


Using the code is easy.


It's that simple. And the technique can be used to get at other VBScript functionality. In fact, .Language can have values other than "VBScript", making it possible to interface to any language with a Windows Scripting Host presence.

© Copyright Bruce M. Axtens, 2009

7 comments:

Unknown said...

Be aware that the Microsoft script control is not supported on Vista.

Bruce M. Axtens said...

Hmmm ... not good news. Interestingly a VB6 application I'm developing on Windows 7, using MSScriptControl, works fine. So "not supported" evidently doesn't mean "not there".

Paphnutius Stylites said...

It seems to be running perfectly happily on W7 for me. Excellent and elegant solution to a pernicious problem.

EVI INDRA EFFENDI said...

for more source code please visit to my blog http://vb6stuff.blogspot.com

Anonymous said...

It is not working if my string contains newline chars VBCRLF

Bruce M. Axtens said...

I shall have a look at it, Anonymous, and get back in a few days time.

anjali kulkarni said...

The function escape is not working correctly if string to evaluate contains " ) vbcrlf.
What to do?