Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Instr Function 2

Status
Not open for further replies.

Bluejay07

Programmer
Joined
Mar 9, 2007
Messages
780
Location
CA
Hello,

I am using VB6 and have a question regarding the Instr() function.

If I have a string similar to:
1, 11, 2, 12, 3, 17, 4, 20, 5, 18, 19

Say this string is stored in m_strNums

I want to find if a particular value can be found in the string, except I am facing the limitations of this function.

If I were to use:
InStr(1, m_strNums, 8)
The function returns 33 as 8 is found in the 33rd position; however, the 8 found is part of 18.

How can I search the string for a single value? (I hope this is clear).
 
You need to be looking for ", 8," not just "8".
 
Adding to HughLerwill's suggestion....

InStr(1, ", " & m_strNums & ",", ", 8,")

This should accommodate searching for the first or last item.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Thank you both for your help.

Things seem to work with your suggestions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top