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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search An Array 1

Status
Not open for further replies.

RebelFox

Programmer
Jun 16, 2002
62
0
0
GB
I need to search a string array for an occurance that matches a string. I thought this would be easy but the only command I could find in MSDN is the ASCAN command.
Strangely VB does not recognise it. The syntax is correct but VB just doesn't seem to have it in its vocabulary.

Is this the best way to scan for an array occurance and what do I have to do to get VB to recognise ASCAN?

Thankyou.
 
Do you need to know the index of the string? If you just need to know 'Does strTest exist in one of the elements of arrData', then this should work:

strTemp = Join(arrData, ";")
If InStr(strTemp, strTest) > 0 Then
'Do whatever you do if it is here
Else
'Do whatever you do if it isn't here
End If

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
RebelFox,

There are lot of ways to do this; look at Instr and Mid functions...
 
Try Split? It not only will tell you that it (the Target) does exist, but the number of occurances.



MichaelRed
mlred@verizon.net

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top