Lookup String in Text

O

okelly

Hi All

I'm trying to query a string containing a list of operating systems
types and return the operating system family to me. eg "Windows NT" is
a member of "Windows" etc.

The code below returms the correct result only when the string EXACTLY
matches the code syntax, (including whitespaces, gaps, punctuation
etc...)

What syntax do I use if the string CONTAINS the pVal? I've tried

"If pVal Like "Windows NT" Then...etc.. but it's not working..

I need something like "If pVAl contains "Windows" then Operating System
= "Windows"

Thanks
Conor




Code:
--------------------

Function OperatingSystem(pVal As String) As String

If pVal = "Windows 2000 Server SP4" Then
OperatingSystem = "Windows"

ElseIf pVal = "Windows NT" Then
OperatingSystem = "Windows"
Else
OperatingSystem = "Other"
End If

End Function
 
K

Kaak

Function OperatingSystem(pVal As String) As String

If InStr(pVal, "Windows") Then
OperatingSystem = "Windows"
Else
OperatingSystem = "Other"
End if

End Functio
 
B

Bob Phillips

Function OperatingSystem(pVal As String) As String

If LCase(pVal) Like "*windows 2000*" Then
OperatingSystem = "Windows"

ElseIf LCase(pVal) Like "*windows nt*" Then
OperatingSystem = "Windows"
Else
OperatingSystem = "Other"
End If

End Function

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top