2011-02-13 57 views
0

我在VB中是新的,而我做我的功課,我所要做的就是一個珠寶盒,我需要把9號在9個文本框,並確認他們是不是同樣,我正在通過TextChanged事件來做這件事。驗證所有文本框在VB

我確實有一些代碼,但是不完整。並沒有真正的工作。

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 
+0

你可能會張貼你的代碼嗎? –

+0

它的很多它不會讓我:( – itsmedavid

回答

1

添加表單上命令按鈕...,把你的代碼有..

使用條件語句一樣,如果別人..

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

商祺!

+0

我做的那個低谷,這就是笑容易,但我的意思是我們r緊靠9個文本框說話,那將是大量無用的代碼,我想知道的更簡單的方法 – itsmedavid

+0

你可以發佈您的代碼@itsmedavid? – Crimsonland

+0

'code'私人小組TextBox1_TextChanged(BYVAL發件人爲System.Object的,BYVALË作爲System.EventArgs)把手TextBox1.TextChanged,TextBox2.TextChanged,TextBox2.TextChanged,TextBox3.TextChanged,TextBox4.TextChanged ,TextBox5.TextChanged,TextBox6.TextChanged,TextBox7.TextChanged,TextBox8.TextChanged,TextBox9.TextChanged 否則(則IsNumeric(TextBox1.Text))然後 MSGBOX( 「ERROR」) 結束如果 昏暗一個作爲整數 End Sub'code' – itsmedavid

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