Maximum number of conditions in an IF statement? (Visual Basic 6)

Does anyone know if there a maximum number of conditions that can be evaluated within one If statement in Visual Basic 6?  (i.e. If ...or....or....or....or....or...or...or...or...or...or etc.)

I am aware that including a large number of conditions within an If statement is poor programming practice, and I am equally aware that there are many better ways of going about this, however this is out of my control.

Many thanks!
Who is Participating?
joboyConnect With a Mentor Commented:
There doesn't appear to be any explicit limit.  However, in reality there is a limit because you're only allowed 1024 characters per line, you are then forced to use a Line Continuum character - add to this that you can only use a maximum of 23 Line Continuum characters, then you've reached your limit.  Thus depending on the length of each condition between the 'or' statements will determine the maximum number of or's allowed!

Hope that makes sense,
I'm not skilled in VB, but I think there is no maximum number condition. As long as you have a valid logical expression, everything is ok.
If you need so much or or or ..

Perhaps better:
Select Case YourField
   Case 1, 2, ...
    Case 555, 66 ...
   case else
end select
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

helphireAuthor Commented:
I am aware that there are better ways of doing this (e.g. Select case) but as I said - this is the way it is being done and I have no control over it. Can anyone provide a definitive answer?
pritaeasSoftware EngineerCommented:
I think the If length is bounded by a maximum line length, if any. This should be in the help.
why do you say "this is the way it is being done "?  BY whom?

pritaeasSoftware EngineerCommented:
Haha, then the easiest way will be to call a function, which will contain all conditions. Then there is theoretically no limit... But hey, if you really want to use that method, make sure your variables are _very_ short: If a or b or c or d .....

Signing off... have fun with it.

There is no limit specified any where in the records, but I myself checked to see what happens. What I check was

if Text1.text="1" or Text2.text="2" or ....

It throwed an error saying complex syntax after the count 600. An another error that happens memory reference error.

I dont expect you will have 500 arguments. But there is always a better way to do this using a switch statement, or apply much more into your program.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.