开发者

verify all text boxes in VB

I'm new in VB, and I'm doing my homework, what I have to do is a magicbox, I need to put 9 numbers in 9 text boxes, and verify that they are not the same, I'm doing it trough the TextChanged event.

I do have some code, but is incomplete. And doesn't really work .

Private Su开发者_开发知识库b 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


Add Command Button on your form...And Place your code there..

USE Conditional statement like if else..

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

Regards!


i think the following code will help you.

    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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜