验证VB中的所有文本框

时间:2011-02-13 23:54:29

标签: vb.net authentication

我是VB的新手,我正在做作业,我要做的就是魔术盒,我需要在9个文本框中放9个数字,并验证它们不一样,我是通过TextChanged事件来做。

我确实有一些代码,但不完整。并没有真正起作用。

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 
TextBox1.TextChanged,
TextBox2.TextChanged,
TextBox2.TextChanged,
TextBox3.TextChanged,
TextBox4.TextChanged,
TextBox5.TextChanged,
TextBox6.TextChanged,
TextBox7.TextChanged,
TextBox8.TextChanged,
TextBox9.TextChanged 

If Not (IsNumeric(TextBox1.Text)) 
Then 
MsgBox("ERROR") 
End If 
Dim a As Integer 

End Sub

2 个答案:

答案 0 :(得分:1)

在表单上添加命令按钮...并将代码放在那里..

USE条件语句,如if else ..

If textbox1 <> texbox2 or textbox3 <> texbox4  then
MsgBox "We are not equal"
Else
MsgBox "We are equal"

问候!

答案 1 :(得分:0)

我认为以下代码可以帮助您。

    Private Sub btn_generate_text_array_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click 'button click will generate 10 text boxes in form
            Dim j As Integer
            For j = 0 To 10
                ReDim Preserve c(j)
                c(j) = New TextBox
                c(j).Name = "txt" & j
                c(j).Parent = Me
                c(j).Top = j * c(j).PreferredHeight + 2
                c(j).Tag = j
                c(j).Visible = True
            Next
        End Sub

        Private Sub btn_process_input_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            For j = 0 To 10 
                For k = j + 1 To 10 
                    If Val(c(j).Text) = Val(c(k).Text) Then
'if identical values ware found then the back color of both the text boxes will turn to red
                        c(j).BackColor = Color.Red
                        c(k).BackColor = Color.Red
                        MsgBox("same values found")
                    End If
                Next
            Next
        End Sub