Help?! validating blank fields

BlueOysterCult

Regular
Joined
Oct 3, 2003
Messages
84
Hello All
I am getting used to VB.net - I remember (I think) in VB 6 that if a txtBox.text = "" then it was considered a blank field. I can't get this code to work - I keep getting the message box (error) but I want the ELSE statement to work if it is ( the fields) filled in.

Code


Code:
Private Sub btnOrder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOrder.Click
        If txtName.Text = "" Or cmbBrand.Text = "" Or cmbStyle.Text = "" Or cmbSize.Text = "" _
        Or (radMensShoes.Checked = False Or radWomensShoes.Checked = False) Then

            MsgBox("Please fill in all fields" & Environment.NewLine & "you may leave width unchecked")
        Else
            txtBox1.Text = ("Thank You " & txtName.Text & Environment.NewLine & "Men's Shoes:" & radMensShoes.Checked & _
           Environment.NewLine & "Women's Shoes:" & radWomensShoes.Checked & Environment.NewLine & "Brand: " & cmbBrand.Text & Environment.NewLine & _
           "Style: " & cmbStyle.Text & Environment.NewLine & "Size: " & cmbSize.Text & Environment.NewLine & "Width:" & chbWidth.Checked)


        End If



    End Sub

Thanks
Rob
 
Replace this:
Visual Basic:
(radMensShoes.Checked = False Or radWomensShoes.Checked = False)
with
Visual Basic:
(radMensShoes.Checked = False AndAlso radWomensShoes.Checked = False)
Otherwise it will fail unless BOTH checkboxes are checked.

Also, you should use OrElse instead of Or in these cases, as it is more efficient.
 
Back
Top