I am checking a couple of textboxes in my datarows. If the first textbox (event association 1) is not blank and it does not contain the word business, but the date of birth mtb is empty, then the statement is true and a messagebox will be displayed. Right now, I just don't understand the error, while debugging, regarding string conversion to boolean is not valid?

 For Each Personrow As DataRow In PFC_Xpress.Tables("Person").Rows
                If EVENT_ASSOC1.Text <> "" & EVENT_ASSOC1.Text <> "Business" Then
                    For Each Personrow1 As DataRow In PFC_Xpress.Tables("Person").Rows
                        DOB.TextMaskFormat = MaskFormat.ExcludePromptAndLiterals
                        If DOB.Text = "" Then
                            Not_Business = True & MessageBox.Show("missing dob")
                        End If
                    Next
                End If
            Next

Recommended Answers

All 8 Replies

The statement

Not_Business = True & MessageBox.Show("missing dob")

is invalid. MessageBox returns type DialogResult. You have to compare that result to something to get a boolean. Example

If MessageBox.Show("missing dob") = DialogResult.yes

What are you trying to accomplish with that statement?

When a button is clicked, some conditional statments are run through. If the user has entered anything besides "business" in the event association box, but forgets to add the date of birth, a messagebox will be displayed, informing them they have forgotten to add the date of birth.

If DOB.Text = "" Then
    Not_Business = True
    MessageBox.Show("missing dob")
End If

Thank you for help Rev. I'll give that a try when I get home. More importantly, thanks for the explanation as to the error!

Hey Rev, I see how simply this code works, but I'm also trying to take into consideration that if the user selects business, the dob field does not need to be completed.

Try this
if Not_Business or isempty(DOB.text) then
..The rest of your code here

the second part of the statement - isempty(DOB>text) will only be evaluated if Not_Business is true

hope this helps

That's not quite true. To get the short-circuit form you have to use

If Not_Business OrElse IsEmpty(DOB.Text) Then

If you use Or or And instead of OrElse or AndAlso then the entire expression is evaluated. This can be a problem if the second part of the expression can return an error under some conditions. For example, checking the value of the first item in a recordset will cause an indexing error if rec.EOF is true. So

If Not rec.EOF And rec(0).Value = 5 Then

could cause an error whereas

If Not rec.EOF AndAlso rec(0).Value = 5 Then

will not because the second part is evaluated only if EOF is False.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.