0

I have this if statement right here:

If lbl1.Text <> "Good" Or lbl2.Text <> "Good" Or lbl3.Text <> "Good" Then
        MsgBox("Something.")
        Exit Sub
    End If

This works fine, but I also need to attach another condition to it, but for some reason I am drawing a blank on it. I need it to also pass that it is ok for lbl2 & lbl3 to be an empty string. In order words, if lbl1.text = "Good" then it is ok for lbl2 & lbl3 to be empty, therefore it will not exit sub.

2 Answers 2

2

If you look at it from the other way around, what you're saying is that if any one of the labels says "Good", then don't enter this statement, so, you could say enter this statement if that is not the case.

In other words:

If Not(lbl1.Text = "Good" Or lbl2.Text = "Good" Or lbl3.Text = "Good") Then
    MessageBox.Show("Something.")
End If

Hope that does the trick!

Sign up to request clarification or add additional context in comments.

1 Comment

I always forget about If Not. I gotta get out of the habit of trying to fit the conditions with <>
1

What about a statement like this?

If Not ((lblA.Text = "Good" OrElse lblA.Text = String.Empty) AndAlso _
            (lblB.Text = "Good" OrElse lblB.Text = String.Empty) AndAlso _
            (lblC.Text = "Good" OrElse lblC.Text = String.Empty)) Then
        MessageBox.Show("Something.")
    End If

1 Comment

Dropped the Exit Sub in there and this did what I needed. Thanks for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.