检查多个 TexBox 中的特定文本
Check for certain text in multiple TexBoxes
我正在为朋友制作恶作剧防病毒程序。部分软件需要"activation"删除"virus"。当我单击按钮时我有 4 个 TextBoxes 我想要检查所有 4 个 TexBoxes 的文本“0000”。当我有一个 TextBox 时它工作得很好,但我需要在消息框出现之前检查所有 4 个框。我希望这是有道理的。 See image here
[编辑]我要说的是我是个编程新手。
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = "0000" Then
MsgBox("Registered")
Me.Hide()
End If
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
End Class
有很多方法可以做你想做的事。这是您可以构建的非常简单的一个:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' check all the TextBoxes in the array. Return if one isn't valid
For Each textbox As TextBox In {TextBox1, TextBox2, TextBox3, TextBox4}
If textbox.Text <> "0000" Then
Return
End If
Next
' If all TextBox contains the valid string, this will appear
MsgBox("Registered")
Me.Hide()
End Sub
玩得开心!
编辑:
要有 4 个不同的字符串:只需链接 4 个检查。像这样:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' If all TextBox contains the valid string, this will appear
If TextBox1.Text = "0000" AndAlso TextBox2.Text = "1111" AndAlso TextBox3.Text = "2222" AndAlso TextBox4.Text = "3333" Then
MsgBox("Registered")
Me.Hide()
End If
End Sub
我正在为朋友制作恶作剧防病毒程序。部分软件需要"activation"删除"virus"。当我单击按钮时我有 4 个 TextBoxes 我想要检查所有 4 个 TexBoxes 的文本“0000”。当我有一个 TextBox 时它工作得很好,但我需要在消息框出现之前检查所有 4 个框。我希望这是有道理的。 See image here
[编辑]我要说的是我是个编程新手。
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If TextBox1.Text = "0000" Then
MsgBox("Registered")
Me.Hide()
End If
End Sub
Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged
End Sub
End Class
有很多方法可以做你想做的事。这是您可以构建的非常简单的一个:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' check all the TextBoxes in the array. Return if one isn't valid
For Each textbox As TextBox In {TextBox1, TextBox2, TextBox3, TextBox4}
If textbox.Text <> "0000" Then
Return
End If
Next
' If all TextBox contains the valid string, this will appear
MsgBox("Registered")
Me.Hide()
End Sub
玩得开心!
编辑:
要有 4 个不同的字符串:只需链接 4 个检查。像这样:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' If all TextBox contains the valid string, this will appear
If TextBox1.Text = "0000" AndAlso TextBox2.Text = "1111" AndAlso TextBox3.Text = "2222" AndAlso TextBox4.Text = "3333" Then
MsgBox("Registered")
Me.Hide()
End If
End Sub