Page 1 of 2 12 LastLast
Results 1 to 15 of 26
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Regular Expressions - Stephen Kleene (Word97/SR2)

    Kevin has made his customary excellent reference, this time to http://www.zytrax.com/tech/web/regex.htm , and I am a happy customer.

    This post suggests a code fragment:

    <pre>Sub test()
    Dim regex As Object
    Set regex = CreateObject("vbscript.regexp")
    regex.Pattern = "[^A-Za-z]"

    MsgBox regex.test("Kevins") ' -->false
    MsgBox regex.test("Kevin's") ' -->true
    MsgBox regex.test("Kevins2") ' -->true

    Set regex = Nothing
    End Sub
    </pre>


    Problem 1: I have IE5.0 installed (and working), but what reference (Tools, References) do I add to get at this vbscript object. (I have a sense of deja vu, that I was trying to do this a couple of weeks ago and got diverted; this time I'm going to be my usual tenacious self).

  2. #2
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Regular Expressions - Stephen Kleene (Word97/SR2)

    Chris,

    See if you can find an entry for Microsoft VBscript Regular Expressions 5.5 or suchlike in your reference listing.

    If not locate VBScript.dll and set a reference to that.

    Andrew

  3. #3
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Regular Expressions - Stephen Kleene (Word97/SR2)

    Here's the only wrench in the works that I have discovered. If you add

    c:SystemFolderRootsystem32vbscript.dll

    to your list of references (in VBA anyway), you'll get this:

    Microsoft Script Globals

    as the referenced library. But that's not right. I mean, the Reg Ex
    object is there all fine and dandy. But I can't use
    intellisense to get the methods, etc. Instead I search google
    and MS for vbscript regex syntax help.

    If somebody figures this out, please post back. It would be nice
    to get the intelli on this...
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Regular Expressions - Stephen Kleene (Word97/SR2)

    This code snippet uses late binding - regex is declared as an Object, not as a specific type. It is assigned a value by CreateObject; the only thing required for this is that VBScript is installed on your PC. You don't need to set a reference. The downside is that you can't use IntelliSense to see a list of properties and methods of regex.

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Regular Expressions - Stephen Kleene (Word97/S

    Thanks Andrew, I have it now.

  6. #6
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Regular Expressions - Stephen Kleene (Word97/S

    > c:SystemFolderRootsystem32vbscript.dll

    Thanks Kevin. This worked.

    I think it was the lack of intellisense that made me think it wasn't working when I tried it a couple of weeks back.

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Regular Expressions - Stephen Kleene (Word97/S

    > The downside is that you can't use IntelliSense

    Thanks Hans.


    If I've understood your message correctly, it was a decision by the creators of VBScript.DLL to use late binding that prevents us from obtaining the Intellisense?

  8. #8
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Regular Expressions - Stephen Kleene (Word97/S

    Chris, I think you may have mistaken Hans's remarks. He suggest that th ecod esnippet you posted at th etop of the thread uses late binding and should run with need for a reference to be set, provided that VBScript.dll is available and registered on the system. If you do set a reference to VBScript, the following does the same job, but does provide the intellisense facility as you code.<pre> Dim regExp As New regExp
    regExp.Pattern = "[^A-ZA-z]"
    MsgBox regExp.Test("Kevins")
    MsgBox regExp.Test("Kevin's")
    MsgBox regExp.Test("Kevins2")</pre>

    Andrew.

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Regular Expressions - Stephen Kleene (Word97/S

    > do set a reference to VBScript, the following does the same job,

    Hmmm. Odd. Maybe this is the logjam I met a short while ago.

    I now have in my Normal Template:
    <pre>Sub TestLate()
    Dim regex As Object
    Set regex = CreateObject("vbscript.regexp")
    regex.Pattern = "[^A-Za-z]"
    MsgBox regex.test("Kevins") ' -->false
    MsgBox regex.test("Kevin's") ' -->true
    MsgBox regex.test("Kevins2") ' -->true

    Set regex = Nothing
    End Sub

    Sub TestEarly()
    Dim regExp As New regExp
    regExp.Pattern = "[^A-ZA-z]"
    MsgBox regExp.test("Kevins")
    MsgBox regExp.test("Kevin's")
    MsgBox regExp.test("Kevins2")
    End Sub
    </pre>


    The TestEarly causes a syntax error until I add a reference to (my machine) C:WINDOWSSYSTEMVBSCRIPT.DLL which appears in WordVBA as "Microsoft VBScript Global" and has a slash-one appended C:WINDOWSSYSTEMVBSCRIPT.DLL1.

    With the reference added, the TestLate runs as predicted, false true true, but compiling the TestEarly generates an error with "regExp As New regExp" highlighted: "User-defined type not defined".

    Here's a DOS DIR of my only VBScript.dll:

    <pre>VBSCRIPT DLL 426,256 04-23-99 10:22p VBSCRIPT.DLL
    </pre>



    I reason : Clearly VBSCript.dll exists and is accessible to VBE, because the TestLate executes and delivers correct results.

  10. #10
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Regular Expressions - Stephen Kleene (Word97/S

    Chris,

    You need a reference to Microsoft VBscript Regular Expressions 1.0 or Microsoft VBscript Regular Expressions 5.5 rather than Microsoft VBScript Global. All three references use VBScript.dll, but the 2 regular expression references use VBSCRIPT.DLL2 or VBSCRIPT.DLL3. Presumable the VBScript.dll canbe initiaised differently for compatibility reasons.

    Andrew C

  11. #11
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Regular Expressions - Stephen Kleene (Word97/S

    > You need a reference to Microsoft VBscript Regular Expressions

    Andrew, thanks for the peserverance..

    There's the rub!

    I don't seem to be able to raise those through "Tools, References".

    I've scrolled through the list looking for the term "Microsoft VBscript Regular Expressions" in the window. I've scrolled again looking in the label area at the foot of the GUI for a second occuurence of VBSCript.dll. To no avail.

    I don't suppose I can fudge the /2 or /3, nor do I suppose I ought to be able to.

    Clearly (?) I have the DLL; it is sitting where it should be, and is coming into play for TestLate.


    Is it perhaps a failing of my environment (Win98SE/Office97/SR2)?

    Kevin mentioned IE5; I have that installed AND I use it (occasionally, to test web sites that fail under Mozilla1.0).

    Does the date/time stamp on my VBScript.DLL match yours?

  12. #12
    Gold Lounger
    Join Date
    Feb 2001
    Location
    Dublin, Ireland, Republic of
    Posts
    2,697
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Re: Regular Expressions - Stephen Kleene (Word97/S

    Chris,

    Accordingg to this MSDN entry , version 5 of VBScript.dll is the first to include the RegExp object. I attach a list of applications that include VBSript version 5.

    I see that both IE 5.0 and Windows 98SE are included. Should you have your 98SE CD, see if you can extract it from the Cab file Win98win98_43.cab

    The version on my Office system (NT) is Sep 14 2001, but that may because I have IE 6 installed.

    Andrew
    Attached Files Attached Files

  13. #13
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Regular Expressions - Stephen Kleene (Word97/S

    > see if you can extract it from the Cab file Win98win98_43.cab

    I can, and did, to a separate folder (C:200302025).

    Reentered Word, disconnected my C:WindowsSystem version, then connected my C:200302025 version. Same results. TestLate works, TestEarly bombs.

    I've read your attachment and inspected the date from the CAB. Both give a time stamp of 4-23-99 (as I reported in an earlier post), so I appear to have the MS recommended version, but can't get to use it as a New Object. IEExplorer is given a date stamp of 3/18/1999, even earlier than mine. I note that all file sizes are the same, so perhaps the variety of dates reflects merely the day on which they burned the CD.


    Maybe I'll try to d/l IE6 tonight and see if that helps.

  14. #14
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Regular Expressions - Stephen Kleene (Word97/S

    .... so then I thought to do some housecleaning, just in case.

    Nothing much has changed, but the attached BitMap snapshot shows that TonyArts RegCleaner detects my temporary DLL as being VBSCRIPT.DLL2 (see the last line in the list of registry keys), but when I reenter Word in disbelief, Tools References does NOT show that mystical 2.


    (Is it something I said? Something I ate?)


    I have decided NOT to remove the registry entry. Yet




    Anyone: Are you able to play with TestEarly using this 4-23-99 VBSCRIPT.DLL?
    Attached Files Attached Files

  15. #15
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Regular Expressions - Stephen Kleene (Word97/S

    I think you're going to need a wrapper dll for vbscript.dll in order to
    get the regex objects exposed to VB/VBA and thus early binding.

    I recommend (unless you can write such a puppy or glean one from
    a fellow MDS member) you live with lateness in binding and just use
    google, MSDN, etc. to obtain the object model particulars.

    Therefore, remove the reference to MS Global Objects since
    it's not necessary.

    Charter Member, MDS,
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •