Solved

InStr Question

Posted on 2002-05-02
9
151 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
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 20

Accepted Solution

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

Expert Comment

by:rspahitz
Comment Utility
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
Comment Utility
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
 
LVL 15

Expert Comment

by:ameba
Comment Utility
or:
    If strDude Like "*" & strFind & "*" Then
        MsgBox "Found in string"
    End If
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 15

Expert Comment

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

Expert Comment

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

Author Comment

by:ADawn
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now