tags:

views:

304

answers:

2

I'm expecting to see a reference to VBscript Regular Expressions 5.5 by adding the path c:\windows\system32\vbscript.dll\3 to ms-access via Tools > References. However the directory tree only shows me the full path without the ending "\3"

What does the "\3" mean (version number?), what is it the correct name for it? How do correctly add this reference to my access project? Thanks.

+1  A: 
Robert Harvey
I'm using MS-Access 97 and Microsoft VBScript Regular Expressions 5.5. does not seem to be on my default list of references
bizl
am i missing a dll?
bizl
vbscript.dll should be in c:\windows\system32.
Robert Harvey
Fair warning, though. All of the examples I am seeing on the web are doing late binding. http://technet.microsoft.com/en-us/magazine/cc462811.aspx
Robert Harvey
That's right. I read 'elsewhere': "Regular expression support comes with Windows Script 5.0".. downloaded the latest 5.6, run, and then lost all clues about where the new dll could be.... On other hand, late binding just worked, so I'll accept that. Great pointer - ta!
bizl
A: 

Better yet, don't add a reference to it. Instead, use late binding. This means you'll use plain-vanilla object variables instead of the RegExp library's data types:

  Dim objRegEx As Object
  Set objRegEx = CreateObject("VBScript.Regexp")

Thus, you don't need to worry about the library version installed on the particular computer. The speed difference is pretty neglible for one call to it, but if you're going to use it regularly, create a public function like this:

  Public Function RegEx() As Object
    Static objRegEx As Object

    If objRegEx Is Nothing Then
       Set objRegEx = CreateObject("VBScript.Regexp")
    End If
    Set RegEx = objRegEx
  End Function

Then you don't have to do anything at all -- just use RegExp the same way you'd use a variable that pointed to its top-level object. This will automatically initialize the first time you use it and will then persist until you close the application.

If you're concerned about cleaning up before closing down, you can do this:

  Public Function RegEx(Optional bolClose As Boolean = False) As Object
    Static objRegEx As Object

    If bolClose Then
       Set objRegEx = Nothing
       Exit Function
    End If
    If objRegEx Is Nothing Then
       Set objRegEx = CreateObject("VBScript.Regexp")
    End If
    Set RegEx = objRegEx
  End Function

And in your app's shutdown routine call it thus:

  Call RegEx(True)

And bob's your uncle!

David-W-Fenton
v. elegant. Nice. I've seeen advise crediting late binding as the best approach for access over and over and less headache. ta!
bizl