PDA

View Full Version : Solved: item.subject and regular expressions



next
06-19-2012, 10:09 AM
I can't get my regex function to work with item.subject. It's complaining that data type is wrong. I thought item.subject returned r/w string :dunno
Here's my complete code:
Sub test()
Dim session As NameSpace
Dim folders As folders
Dim inbox As MAPIFolder
Dim item As Object

Set session = Application.session
Set folders = session.folders
Set inbox = folders("myfolder").folders(" (dstolearenco@cleanway.com)Customers").folders("test")

For Each item In inbox.Items
If regex_match(item.Subject, "\D{2}-\d{3}") Then
Debug.Print item.Subject & " - found"
Else
Debug.Print item.Subject & " - not found"
End If

Debug.Print item.Subject
Next item

End Sub
Function regex_match(value As String, _
pattern As String, _
Optional multiline = False, _
Optional globl = False, _
Optional ignoreCase = False) As String

Dim re As Object, REMatches As Object

Set re = CreateObject("vbscript.regexp")

With re
.multiline = multiline
.Global = globl
.ignoreCase = ignoreCase
.pattern = pattern
End With

Set REMatches = re.Execute(value)
regex_match = REMatches(0)
End Function
Thanks.

next
06-19-2012, 11:49 AM
i fixed it:
Function regex_match(value As String, _
pattern As String, _
Optional multiline = False, _
Optional globl = False, _
Optional ignoreCase = False) As String

Dim re As Object, REMatches As Object

Set re = CreateObject("vbscript.regexp")

With re
.multiline = multiline
.Global = globl
.ignoreCase = ignoreCase
.pattern = pattern
End With

If re.test(value) <> 0 Then
Set REMatches = re.Execute(value)
regex_match = REMatches(0)
Else
regex_match = False
End If
End Function