3

Here i have my simple code, containt list of arrays and 2 text boxes, when i press button script must check if text form Textbox2 is found in list of array. Can you help me to fix it ? Thanks !

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim pins() As String = {"dgge", "wada", "caas", "reaa"}
    If TextBox2.Text = pins() Then
        TextBox1.Text = "Succes"
    End If End Sub
1

3 Answers 3

1

If you want to use LINQ, you can just do this:

If pins.Contains(TextBox2.Text) Then
    TextBox1.Text = "Success"
End If

Otherwise, the easiest option would be to use a List instead of an array:

Dim pins As New List(Of String)(New String() {"dgge", "wada", "caas", "reaa"})
If pins.Contains(TextBox2.Text) Then
    TextBox1.Text = "Success"
End If

But, if you must use an array, you can use the IndexOf method in the Array class:

If Array.IndexOf(TextBox2.Text) >=0 Then
    TextBox1.Text = "Success"
End If
Sign up to request clarification or add additional context in comments.

Comments

0
If Array.IndexOf(pins, TextBox2.Text) <> -1 Then
    TextBox1.Text = "Succes"
End If End Sub

Comments

0
If pins.IndexOf(TextBox2.Text) >= 0 Then
    TextBox1.Text = "Founded"
End If

Or if you use List(Of String) instead of array:

If pins.Contains(TextBox2.Text) Then
    TextBox1.Text = "Founded"
End If

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.