-1

trying to figure out how I can search for a string in my arrays. As of now, I only figured out how to search through integers. My array is like this:

Dim IDno() As String = {264, 951, 357}
Dim author() As String = {"Peter", "Nathan", "Sandy"}

So as of now, if someone types in the number 951, my listbox will display:

ID#: 951

Name: Nathan

I want to know how I can allow users to search for names instead and it will display the ID# and the Name.

4
  • 1
    This question may help you: stackoverflow.com/questions/16713474/… Commented May 4, 2017 at 9:19
  • Possible duplicate of VB.NET Find a string in an Array Commented May 4, 2017 at 11:26
  • @AndrewMorton You mean, a duplicate of a duplicate?! Commented May 4, 2017 at 16:27
  • @David Yes, this seems to be more of a match to the one I referred to (and muffi spotted in the first place) than the root one. Of course, the reader can follow back to the root one. Commented May 4, 2017 at 17:39

1 Answer 1

0

You can do this using Array.FindIndex - Only if all values/IDs are going to be unique.

Something along the lines of this should do the trick for you.

Dim ind As Integer = Array.FindIndex(IDno, "yourID")
Dim name As String = author(ind)

I've not got VS to hand to test this but off the top of my head, that should work. Although, as I said, it's only going to work if all the ID numbers are unique. (And obviously replace "yourID" with the ID you're using).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.