Solved

InStr Question

Posted on 2002-05-02
9
152 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
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
 
LVL 15

Expert Comment

by:ameba
ID: 6987590
or:
    If strDude Like "*" & strFind & "*" Then
        MsgBox "Found in string"
    End If
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DO Loop not working 4 72
Macro which automatically sends attachment to Outlook 14 61
Paint/Redraw window while dragging 16 68
vb6 connector to mongodb 2 51
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

867 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

12 Experts available now in Live!

Get 1:1 Help Now