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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
If strDude Like "*" & strFind & "*" Then
MsgBox "Found in string"
End If
or (VB6 only):
If UBound(Filter(Array(strDud e), strfind)) > -1 Then
MsgBox "Found in string"
End If
If UBound(Filter(Array(strDud
MsgBox "Found in string"
End If
want more? :-)
If InStrRev(strDude, strfind) > 0 Then
MsgBox "Found in string"
End If
If InStrRev(strDude, strfind) > 0 Then
MsgBox "Found in string"
End If
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
Is there a function that will convert to proper case, then make the search for a particular item within the string?
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
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,,vbT extCompare ) then
...
:this will compare without regard to text case and would give the same results as this:
If InStr(lcase(strDude),lcase (strFind)) then
...
:this will compare without regard to text case and would give the same results as this:
If InStr(lcase(strDude),lcase