' Button which allows the user to enter in there own password
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
Try
If TextBox3.Text & TextBox6.Text & TextBox7.Text & TextBox8.Text > 0 And TextBox4.Text <> "" Then
'input in these textboxes must be numerical
' It adds the passwords which is made by the user himself
ListBox1.Items.Add("Application : " & TextBox4.Text & " Password : " & TextBox3.Text & TextBox6.Text & TextBox7.Text & TextBox8.Text & " Time : " & TimeString & " Date : " & DateTime.Today)
End If
Catch ex As Exception
MessageBox.Show("Please provide correct input")
End Try
我目前正在Visual Basic上制作一个密码生成器,我已经在用户可以自己设置密码的部分中显示了代码,但是我希望有一些错误处理程序,目前我可以使用它,因此显示错误消息如果将非数字信息输入到textbox3,6,7,8中。这可行,但是我想补充两点
1.如果textboxes3,6,7,8为空,则会显示一条错误消息
2.如果textbox4为空,则显示一条错误消息,当前列表框中未打印任何内容,但未显示任何错误消息。
压力
vb的初学者
最佳答案
您实际上并不需要异常处理来进行验证。您可以使用内置方法来执行此操作。
例如,以下代码检查名为ExampleTextBox的texbox是否具有输入,并且输入是有效整数。
If String.IsNullOrEmpty(ExampleTextBox.Text) Then
'no input
Else
'has input, check if number
Dim enteredNumber As Integer
If Integer.TryParse(ExampleTextBox.Text, enteredNumber) Then
'input is a valid integer
Else
'input is not a valid integer
End If
End If
关于vb.net - 在VB中添加错误处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47673883/