Hi,

I am totally lost and I went through a lot of sites about searching within an array, but I could not find any clues. I created the following array :

Private LetterArray() As String = {"A", "B", "C"}

and I don't know how to get the target letter from a "Textbox" and search "SearchButton" for it ?
I have to do the following:
- Get the TargetLetter from the textbox
- Set a Boolean for Found to False (which I did)
- Use for loop For Each Letter in the Array (LetterArray)
- If the Word = the Target
Make Found True
Endif

I appreciate all the help or the hints/sites that I can read for this subject.
Thank you in advance.

Recommended Answers

All 4 Replies

It is not quite clear to me what exactly you try but here is maybe the solution:

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
		Dim target As String = TextBox1.Text

		Dim index As Integer = Array.IndexOf(LetterArray, target)

		If index = -1 Then
			MsgBox("text not found")
		Else
			MsgBox("found text on position: " & index)
		End If

	End Sub

Be aware the search in case sensitive. so it will find A,B,C but not a,b,c.

Thank you for your quick replay, but what if I want the search to accept both cases (upper case and lower case)?

Define all strings in the LetterArray in Lowercase
Private LetterArray() As String = {"a", "b", "c"}
and change the line:
Dim target As String = TextBox1.Text
to
Dim target As String = TextBox1.Text.tolower

Thank you so much for your help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.