Reputation: 1
' 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
I'm currently making a password generator on visual basic , i have displayed the code in the part where the user can make there own password , however i wish to have some error handlers , currently i have got it working so a error message is displayed if non numeric information is entered into textbox3,6,7,8 . this works , however i wish to add two things 1. An error message if textboxes3,6,7,8 are empty 2. An error message if textbox4 is empty , curently nothing is printed in the listbox but no error message is displayed.
P.S A beginner to vb
Upvotes: 0
Views: 50
Reputation: 359
You don't really need exception handling for validation. You can use the built in methods to do this.
For example the following checks if a texbox called ExampleTextBox has input and the input is a valid integer.
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
Upvotes: 3
Reputation: 54427
This doesn't make sense:
If TextBox3.Text & TextBox6.Text & TextBox7.Text & TextBox8.Text > 0 And TextBox4.Text <> "" Then
Say out loud what you want and build it up one piece at a time. You want to display a message if TextBox3
is empty:
If TextBox3.Text = String.Empty Then
You want to display a message if TextBox3
or TextBox6 is empty:
If TextBox3.Text = String.Empty OrElse TextBox6.Text = String.Empty Then
Etc, etc.
Upvotes: 1