Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

like operator

Status
Not open for further replies.

w2e3r4

Programmer
Jan 9, 2011
12
0
0
IT
I created a script to move mail from one folder to another.
the discriminating factor is the subject of the email must contain "IC Voicemail Call Recording".
I use the LIKE operator, this is a piece of code


For Each oMessage In oInBox

If oMessage.Subject like "I: IC Voicemail: Call Recording*" Then
'WScript.Echo oMessage.Subject
If oMessage.Attachments(1) = "" Then
'do nothing no attachment
Else

Set myAttach = oMessage.Attachments

folders are recognised, but LIKE operator doesen't go well!
Any tips?
Thanks
 
Your code uses different pattern. Try (no. and positions of '*'s depend on text structure):
If oMessage.Subject like "*IC Voicemail Call Recording*" Then


combo
 
I have tried "*....*"but not working, he always goes in 'if' cycles
 

How about:
Code:
If [blue]InStr[/blue](oMessage.Subject, "IC Voicemail Call Recording" Then
    ....

Have fun.

---- Andy
 
Is the "IC Voicemail Call Recording" exact string that you search for or it can have additional characters inside, as in your code ("I: IC Voicemail: Call Recording*")?

combo
 
What about this ?
Code:
If oMessage.Subject Like "*IC*Voicemail*Call*Recording*" Then

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Yes it's the exact string!
in thies way It gives me every object of every mail in the folder (I see it in echo message)

should only return the corret subject (when it matchs)

 

I see you have your heart set on LIKE operator, but did you try my InStr?

Have fun.

---- Andy
 
Do you have On Error... somewhere?
Shouldn't your loop start with:
Code:
For Each oMessage In oInBox[!].Items[/!]
?


combo
 
I tryed also IsStr, but it doesn't run!


this is part of the code:

Set oInBox = oSession.Inbox.Messages



On Error Resume Next
Err.Clear


Set oFolder = oSession.Inbox.Folders("gestiti")

For Each oMessage In oInBox

If UCASE(oMessage.Subject) like "*CALL RECORDING*" Then
WScript.Echo oMessage.Subject
If oMessage.Attachments(1) = "" Then
'do nothing no attachment
Else

Set myAttach = oMessage.Attachments
for each oAttachment in myAttach
oAttachment.WriteToFile (thePath & oMessage.Attachments(1))
Next

Set objMovedMessage = oMessage.MoveTo(oFolder.ID)

End If
End If
next

'WScript.Echo "fatto"
oSession.Logoff
set oSession = Nothing
 

What do you get in Immediate Window if you do:
Code:
For Each oMessage In oInBox[blue]
    Debug.Print oMessage.Subject[/blue]
    If UCASE(oMessage.Subject) like "*CALL RECORDING*" Then
    ....

Have fun.

---- Andy
 
Your code seems more like VBS than VBA.
FYI, VBScript lacks the LIKE operator ...
So, you definitively have to use the I[!]n[/!]Str function

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 

***** script completed - exit code: 0 *****
 

Don’t leave us hanging... What’s the solution you used?

Have fun.

---- Andy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top