Link to home
Start Free TrialLog in
Avatar of ADawn
ADawn

asked on

InStr Question

Hello,

VB6(sp5) ADO

How would I find a string within a string and flag it with a message box as in the following?

Dim strDude As String
strFind = "DSMan"
strDude = "DSMan.mdb"

If strFind is in the string: strDude then

msgbox "Found in string"

End IF

Thanks,

ADawn
ASKER CERTIFIED SOLUTION
Avatar of hes
hes
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is this a trick Q?  If you knew to use the Instr function, why not just check the syntax in the help files?
Yes, in help files (F1), or in Object Browser (F2), or just type "Instr(" to see a list of arguments.
This also works:
    If UBound(Split(strDude, strfind)) > 0 Then
        MsgBox "Found in string"
    End If
or:
    If strDude Like "*" & strFind & "*" Then
        MsgBox "Found in string"
    End If
or (VB6 only):
    If UBound(Filter(Array(strDude), strfind)) > -1 Then
        MsgBox "Found in string"
    End If
want more?  :-)
    If InStrRev(strDude, strfind) > 0 Then
        MsgBox "Found in string"
    End If
Avatar of ADawn
ADawn

ASKER

I had the right answer all along. The problem was with the letter CASE when I did the search. DSDUDE wasn't the same as dsdude. So, I converteed both values to lower case, then ran the code. It works fine.

Is there a function that will convert to proper case, then make the search for a particular item within the string?

ADawn
Avatar of ADawn

ASKER

I had the right answer all along. The problem was with the letter CASE when I did the search. DSDUDE wasn't the same as dsdude. So, I converteed both values to lower case, then ran the code. It works fine.

Is there a function that will convert to proper case, then make the search for a particular item within the string?

ADawn
If InStr(strDude,strFind,,vbTextCompare) then
...
:this will compare without regard to text case and would give the same results as this:

If InStr(lcase(strDude),lcase(strFind)) then