rojasa9
rojasa9

Reputation: 21

Is it recommended to have more than one condition in my if statement?

I currently am writing an if statement with a couple of conditions. is there a better or efficient way to write what i have now? Is writing separate if statements better?

If (txtNumberOfVehicles.Text = String.Empty OrElse Not IsNumeric(txtNumberOfVehicles.Text) OrElse CInt(txtNumberOfVehicles.Text) < 0) Then
...
End If

Upvotes: 1

Views: 63

Answers (2)

Mukiibi Ismail
Mukiibi Ismail

Reputation: 41

Actually you can look at breaking it down using if and else if, In some cases the select case can also make a lot of sense to you, Ideally every statement should check one condition for proper management. But if all the conditions you are checking end up with the same do action the you can take your chances.

Upvotes: 0

Al Kepp
Al Kepp

Reputation: 5980

You wrote it correctly, single If command with OrElse is good. Do not try to split it to more if commands.

I would just remove the first part, because it is redundant. String.Empty is not numeric so it will fail in the second part.

Upvotes: 1

Related Questions