|
-
November 20th, 2012, 12:31 PM
#5
Re: exception errors
I used your advice and added a messagebox to check each textbox and worked great with the exception of the masked textbox. I am guessing since there are '(', ')', and '-' already in the textbox that I will need to use a different way of checking to make sure all 10 digits are entered. All i found was the following code which did not work
If telephoneTextbox.Text = nothing then
Here is the code which I have shortened up....
Code:
'Declare Dim statements to check for errors
Dim customerNameError As New System.Text.StringBuilder
Dim shippingAddressNameError As New System.Text.StringBuilder
Dim telephoneError As New System.Text.StringBuilder
Dim productIdentifierError As New System.Text.StringBuilder
'If statement to check if customer name is blank
If String.IsNullOrWhiteSpace(customerNameTextBox.Text) Then
customerNameError.AppendLine("Name required")
customerNameTextBox.Focus()
End If
'Message box for error in customer name
If customerNameError.ToString.Length > 0 Then
MessageBox.Show(customerNameError.ToString, "Error in Customer Information", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
'If statement to check if shipping address is blank
If String.IsNullOrWhiteSpace(shippingAddressTextBox.Text) Then
shippingAddressNameError.AppendLine("Shipping address required")
shippingAddressTextBox.Focus()
End If
'Message box for error in shipping address
If shippingAddressNameError.ToString.Length > 0 Then
MessageBox.Show(shippingAddressNameError.ToString, "Error in Shipping Information", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
'If statement to check if telephone number is valid
If String.IsNullOrWhiteSpace(telephoneMaskedTextBox.Text) Then
telephoneError.AppendLine("Telephone required")
End If
'Message box for error in telephone number
If telephoneError.ToString.Length < 0 Then
MessageBox.Show(customerNameError.ToString, "Error in Telephone Number", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
'If statement to check if product identifier is blank
If String.IsNullOrWhiteSpace(productIdentifierTextBox.Text) Then
productIdentifierError.AppendLine("Product Identifier required")
productIdentifierTextBox.Focus()
End If
'Messagebox for error in product identifier
If productIdentifierError.ToString.Length < 0 Then
MessageBox.Show(productIdentifierError.ToString, "Errors in Purchase Information", MessageBoxButtons.OK, MessageBoxIcon.Error)
Exit Sub
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|