Regular Expressions in Visual Basic 6.0 (VB6):

As I've complained, finding VB6 tutorials now is more difficult since Googling "Visual Basic" pulls back as many or more VB.NET examples [for things like regular expressions] as VB6. Anyhow, here's VB6 Regular Expression code, "inspired" by this tutorial on using regexp from vbscript.

' Step one: Include a reference to "Microsoft VBScript Regular Expressions 5.5"
' in your project.

' From: http://www.brettb.com/VBScriptRegularExpressions.asp
Public Function isMatchFound(strToCheck As String, strRegExpPattern As String)
On Error GoTo errHand

    Dim rexp As RegExp
    Dim bReturn As Boolean
    
    bReturn = False ' assume not a match
    
    Set rexp = New RegExp
    
'This object has three properties: Pattern, IgnoreCase and Global. Pattern
'specifies the Regular Expression that should be searched for. IgnoreCase should
'be True or False depending on whether the search should be case sensitive (the
'default is true). Finally, the Global property should be set to True if the
'search should match all occurrences of the pattern, or False if just the first
'occurrence should be matched:

    With rexp
        .Pattern = strRegExpPattern
        .IgnoreCase = True
        .Global = True
    End With
    
'Once the RegExp object’s properties have been set, it is time to test the
'Regular Expression. This is done using something like the line below. This uses
'the Test method of the RegExp object to see if the Regular Expression is found
'in the StringToSearch string.
    
    bReturn = rexp.Test(strToCheck)
    
    'Finally, the RegExp object is destroyed since it is no longer required.
    Set rexp = Nothing
    
    isMatchFound = bReturn
    
Exit Function
errHand:
    MsgBox Err.Number & " :: " & Err.Description
    isMatchFound = False    ' return false on error
End Function


As an aside, I'm using the new Blogger interface. Combined with Google's GMail, nobody is doing a better job providing a full-functional application crossplatform using just a browser (allowing you to make your OS, computer, even location unimportant). I can check out a preview of my post with a few keystrokes (like in GMail where I can check email, compose, etc with single keys, "elm-like"), and it's even got a nice "rich text-like" editor box. Combined with on-the-fly spellcheck like you find in OmniWeb, these are some of the best apps out there and aboslutely put ActiveX and Java applet kludges to shame.

Labels: