Check textboxs

TMTakas

Member
Joined
Feb 6, 2013
Messages
15
Programming Experience
Beginner
Hi vbdotnetforums ,
i dont know how to check a number of textboxs in the same time
like from the textbox 1 to texbox 10 check if a textbox contains a value
becouse iam trying to program a sudoku , ad you know i need to check textboxs
i think i need to use a loop like :
for i as integer = 1 to 10 then



next

waiting for your help and thx :)
 
i mad this code but still have a error :

Dim array(9) As String
array(0) = TextBox2.Text
array(1) = TextBox3.Text
array(2) = TextBox4.Text
array(3) = TextBox5.Text
array(4) = TextBox6.Text
array(5) = TextBox7.Text
array(6) = TextBox8.Text
array(7) = TextBox9.Text
array(8) = TextBox10.Text


For Each element As Integer In array <-------- Error Here
If TextBox1.Text.Contains(element) Then


MessageBox.Show("!!!!!!!!!!")


End If
Next
 
Think it through. Does this really make sense?
VB.NET:
Dim array(9) As [B][U]String[/U][/B]
array(0) = TextBox2.Text
array(1) = TextBox3.Text
array(2) = TextBox4.Text
array(3) = TextBox5.Text
array(4) = TextBox6.Text
array(5) = TextBox7.Text
array(6) = TextBox8.Text
array(7) = TextBox9.Text
array(8) = TextBox10.Text


For Each element As [B][U]Integer[/U][/B] In array
    If TextBox1.Text.Contains(element) Then
        MessageBox.Show("!!!!!!!!!!")
    End If
Next
If the array contains Strings then why would you be looping through Integers?
 
hi Again , i make this code but still have a problem
    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

        Try

            Dim array(9) As String
            array(0) = TextBox2.Text
            array(1) = TextBox3.Text
            array(2) = TextBox4.Text
            array(3) = TextBox5.Text
            array(4) = TextBox6.Text
            array(5) = TextBox7.Text
            array(6) = TextBox8.Text
            array(7) = TextBox9.Text
            array(8) = TextBox10.Text

            For i As Integer = 0 To array.Length - 1

                If array(i).ToString.Contains(TextBox1.Text) Then

                    MessageBox.Show("Error")
                    Exit For

                Else

                End If

            Next

        Catch ex As Exception

        End Try

End Sub

the problem is when i changed the value of the textbox1 to a value that is in the array the messgae box apairs thats good , but when i delet the value of the textbox the massagebox apairs again !! :(
when i enter a value that is <> the array no messagebox apairs and thats good to

waiting for your respons friends :)
 
Last edited by a moderator:
Firstly, while it's not going to prevent the code working, you still seem not to understand data types properly. You have a String array, right? Every element in the array is a String. If that's the case, why do you need to call ToString here?
VB.NET:
If array(i)[B][U].ToString[/U][/B].Contains(TextBox1.Text) Then
Why do you need to convert a String to a String?

As for the issue, if TextBox1 is empty then TextBox1.Text is an empty String. You're using String.Contains here:
VB.NET:
If array(i).ToString[B][U].Contains[/U][/B](TextBox1.Text) Then
Any time you test whether a String contains an empty String, the result will be True. Think about it. If TextBox1 is empty then you know for a fact that nothing should match it so what's the point of the loop at al in that case?
 
Back
Top