B
Brendan
I am trying to validate the data in all of the text and combo boxes.
The text box validation seems to be working fine, but I am having the
hardest time with the combo box validation. I am not sure why, but I
keep recieving the error message:
"An unhandled exception of type 'System.NullReferenceException'
occurred in homework6.exe Additional information: Object reference
not set to an instance of an object."
here is my code:
option strict on
option explicit on
If IsNumeric(txtcustname.Text) Then
MessageBox.Show("You must enter a name without numbers",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
If txtcustname.Text = "" Then
MessageBox.Show("You must enter a name", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
customer.custname = txtcustname.Text
End If
End If
If cboshirtstyle.SelectedItem.ToString = "" Then
MessageBox.Show("You must select a shirt style", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
If cboshirtsize.SelectedItem.ToString = "" Then
MessageBox.Show("You must select a shirt style", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
If cboshirtcolor.SelectedItem.ToString = "" Then
MessageBox.Show("You must select a shirt style", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
If IsNumeric(txtshirtquantity.Text) Then
customer.shirtquantity = CDbl(txtshirtquantity.Text)
Else
If txtshirtquantity.Text = empty Then
MessageBox.Show("You must enter a shirt quantity",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
MessageBox.Show("You must enter a number for shirt
quantity", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
customer.shirtquantity = CDbl(txtshirtquantity.Text)
End If
End If
I had the If statements set up like this:
If If cboshirtsize.SelectedItem = ""
but that gave me this error message: "Option Strict On disallows
operands of type Object for operator '='. Use the 'Is' operator to
test for object identity."
The text box validation seems to be working fine, but I am having the
hardest time with the combo box validation. I am not sure why, but I
keep recieving the error message:
"An unhandled exception of type 'System.NullReferenceException'
occurred in homework6.exe Additional information: Object reference
not set to an instance of an object."
here is my code:
option strict on
option explicit on
If IsNumeric(txtcustname.Text) Then
MessageBox.Show("You must enter a name without numbers",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
If txtcustname.Text = "" Then
MessageBox.Show("You must enter a name", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
customer.custname = txtcustname.Text
End If
End If
If cboshirtstyle.SelectedItem.ToString = "" Then
MessageBox.Show("You must select a shirt style", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
If cboshirtsize.SelectedItem.ToString = "" Then
MessageBox.Show("You must select a shirt style", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
If cboshirtcolor.SelectedItem.ToString = "" Then
MessageBox.Show("You must select a shirt style", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
If IsNumeric(txtshirtquantity.Text) Then
customer.shirtquantity = CDbl(txtshirtquantity.Text)
Else
If txtshirtquantity.Text = empty Then
MessageBox.Show("You must enter a shirt quantity",
"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
MessageBox.Show("You must enter a number for shirt
quantity", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
customer.shirtquantity = CDbl(txtshirtquantity.Text)
End If
End If
I had the If statements set up like this:
If If cboshirtsize.SelectedItem = ""
but that gave me this error message: "Option Strict On disallows
operands of type Object for operator '='. Use the 'Is' operator to
test for object identity."