PDA

View Full Version : Like expression with AND or OR



ksilenio
10-31-2019, 03:18 PM
Hi to everyone ,how can i use the Like expression with an AND or OR logical operator (If that is possible). Regards

大灰狼1976
10-31-2019, 08:31 PM
Hi ksilenio!
Simple example like below:


Sub test()
Dim s$
s = "abcdef"
If s Like "*def" Or s Like "xyz*" Then MsgBox "Yes" Else MsgBox "No" 'This is right use
If s Like "*def" And s Like "xyz*" Then MsgBox "Yes" Else MsgBox "No" 'This is right use
If s Like ("*def" Or "xyz*") Then MsgBox "Yes" 'This is wrong use
End Sub

snb
11-01-2019, 04:49 AM
To keep your code readable:


Sub test()
c00 = "abcdef"
MsgBox Format(c00 Like "*def" Or c00 Like "xyz*", "yes/no")
End Sub

ksilenio
11-01-2019, 04:32 PM
Thank you very much for your answer
Redards