Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

InStr Question

Posted on 2002-05-02
9
Medium Priority
?
160 Views
Last Modified: 2010-05-18
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
0
Comment
Question by:ADawn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 20

Accepted Solution

by:
hes earned 200 total points
ID: 6987427
Try
If InStr(strDude,strFind) then
  msgbox "Found in string"
End If
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6987451
Is this a trick Q?  If you knew to use the Instr function, why not just check the syntax in the help files?
0
 
LVL 15

Expert Comment

by:ameba
ID: 6987585
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
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 15

Expert Comment

by:ameba
ID: 6987590
or:
    If strDude Like "*" & strFind & "*" Then
        MsgBox "Found in string"
    End If
0
 
LVL 15

Expert Comment

by:ameba
ID: 6987593
or (VB6 only):
    If UBound(Filter(Array(strDude), strfind)) > -1 Then
        MsgBox "Found in string"
    End If
0
 
LVL 15

Expert Comment

by:ameba
ID: 6987594
want more?  :-)
    If InStrRev(strDude, strfind) > 0 Then
        MsgBox "Found in string"
    End If
0
 

Author Comment

by:ADawn
ID: 6988338
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
0
 

Author Comment

by:ADawn
ID: 6988339
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
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 6988821
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
0

Featured Post

Tech or Treat! - Giveaway

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question