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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use Like "*a*" in case statement 1

Status
Not open for further replies.

mattscotney

Programmer
Jul 31, 2002
57
AU
Hi all,

How do I use the like statement within a case statement to catch wildcards?

This is how I think it should be done but it does not work:

Select Case docTypes

Case Like "*egg*"
'Do something....

Case Like "*tea*"
'Do something else....

End Select

Thanks in advance,
Matt
 
Matt,
You could use the InStr() Function with if's don't know how you could do it with a case?
Code:
If InStr(1, docTypes, "egg", vbTextCompare) Then
    'Do Somthing....
Else:
     If InStr(1, docTypes, "tea", vbTextCompare)
         'Do Something else....
     End If
End If

hth
Scoty ::)

"Learn from others' mistakes. You could not live long enough to make them all yourself."
-- Hyman George Rickover (1900-86),
 
JohnYingLing

This looks like the solution i have been looking for BUT...

how can i use this to include "not like" e.g.

Select Case True
Case doctypes Like "*egg*" and not like "*bacon*"
'Do something....
Case doctypes Like "*tea*"
'Do something else....

End Select


Cheers, Craig
Si fractum non sit, noli id reficere
 
hi Craig.

Try this:

Select Case True
Case doctypes Like "*egg*" and not (doctypes Like "*bacon*")
'Do something....
Case doctypes Like "*tea*"
'Do something else....

Andreas Galambos
EDP / Technical Support Specialist
(andreas.galambos@bowneglobal.de)
HP:
 
Cheers Andreas

That worked a treat



Cheers, Craig
Si fractum non sit, noli id reficere
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top