Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if textbox.text exist in array

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
like image 232
Malasuerte94 Avatar asked Feb 23 '26 01:02

Malasuerte94


1 Answers

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
like image 172
Steven Doggart Avatar answered Feb 25 '26 18:02

Steven Doggart



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!