Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OR statement limitations

Status
Not open for further replies.

UnsolvedCoding

Technical User
Jul 20, 2011
424
US
Does anyone know the max number of OR operators that can be in the same line of code?

I haven't found anything to state if there are or are not limits.
 
There is another way: Select Case Statement

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
They don't have to "be in the same line of code":

Code:
If A = 2 Or B = 5 Or C = 10 _
   Or X = 13 Or Y = 66 Then
      ...
End If

I don't think there is a limit (unless someone proves me wrong...)

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
That If statement is one LOC.

If you have if x is 1 or 3 or 17 Then...

Select Case x
Case 1, 3, 17
'True result expressed here
End Select

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
 
I am using or because of others involved. Select case would be a better choice and it looks like that will be where the code ends up.

Right now there are around 8 OR's being evaluated at the same time. To put it politely - ick.
 
If it makes sense for your situation, consider assigning a logical "group" of conditions to a single variable. It could help with comprehending the overall condition.

Code:
Dim thisIsTrue As Boolean
Dim thatIsTrue As Boolean

thisIsTrue = (A = 2 Or B = 5 Or C = 10)
thatIsTrue = (X = 13 Or Y = 66)

If (thisIsTrue Or thatIsTrue) Then

End If
 
I went with a select statement because I was tired of repeating myself with OR.

Thanks to all for the help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top