Groups > Borland > Borland C plus plus builder Active X > Re: Using VBScript.RegExp




Re: Using VBScript.RegExp

Re: Using VBScript.RegExp
Mon, 23 Jul 2007 10:08:54 -070
"nicolasr" <nicolasrREMOVETHISSPAMBLOCKER@gmx.net> wrote in
message
news:46a4abbc@newsgroups.borland.com...

> I recently discovered the VBScript regular expression object
> and thought I could use it in some places. Unfortunately I could
> not get it to work as I hoped.

That is because you are passing char* literals as your parameters.  The
Ole/Variant classes have issues with char* literals being treated as
numerics or booleans instead of strings properly. If you pass your string
parameters as WideString instead, you will get the expected results.  For
example:

    regExp.OlePropertySet("Pattern", WideString("e"));

    ... = regExp.Exec(Function("Execute") <<
WideString("Wheel"));
    or
    ... = regExp.OleFunction("Execute",
WideString("Wheel"));


Gambit


Post Reply
Using VBScript.RegExp
Mon, 23 Jul 2007 15:23:02 +020
Hi all.

I recently discovered the VBScript regular expression object
and thought I could use it in some places. Unfortunately I could
not get it to work as I hoped. Here is an example, maybe someone
can help.

my VBScript:

Dim RegExp
Set RegExp = CreateObject("Vbscript.RegExp")
RegExp.Pattern = "e"
RegExp.IgnoreCase = True
RegExp.Global = True
Dim Matches
Set Matches = RegExp.Execute("Wheel")
MsgBox Matches.Count

the result is 2!

first BCB test:

Variant regExp = CreateOleObject("VBScript.RegExp");
regExp.OlePropertySet("Global", -1);
regExp.OlePropertySet("IgnoreCase", -1);
regExp.OlePropertySet("Pattern", "e");
Variant matches = regExp.Exec(Function("Execute") <<
"Wheel");
ShowMessage(matches.OlePropertyGet("Count"));

the result is 0!


second BCB test:

Variant regExp = CreateOleObject("VBScript.RegExp");
regExp.OlePropertySet("Global", -1);
regExp.OlePropertySet("IgnoreCase", -1);
regExp.OlePropertySet("Pattern", "e");
Variant matches = regExp.OleFunction("Execute", "Wheel");
ShowMessage(matches.OlePropertyGet("Count"));

the result is 0!


third BCB test:

Variant regExp = CreateOleObject("VBScript.RegExp");
regExp.OlePropertySet("Global", -1);
regExp.OlePropertySet("IgnoreCase", -1);
regExp.OlePropertySet("Pattern", "e");
Variant matches = regExp.OleFunction("Execute", "Whee");
//### two 'e' at 
the end
ShowMessage(matches.OlePropertyGet("Count"));

the result is 1 !!!


fourth BCB test:

Variant regExp = CreateOleObject("VBScript.RegExp");
regExp.OlePropertySet("Global", -1);
regExp.OlePropertySet("IgnoreCase", -1);
regExp.OlePropertySet("Pattern", "e");
Variant matches = regExp.Exec(Function("Execute") <<
"Whee"); //### two 'e' 
at the end
ShowMessage(matches.OlePropertyGet("Count"));

the result is 0 again!

So there seem to exist at least two problems. Why is the result always
different from the one I get in VBScript. And why is there a difference
between OleFunction and Exec.

BTW, I'm using BCB5 on Vista.

thanks for any help
Nick 
Post Reply
Re: Using VBScript.RegExp
Mon, 23 Jul 2007 19:55:57 +020
thanks so much! It works now.

Nick
Post Reply
about | contact