Link to home
Start Free TrialLog in
Avatar of helphire
helphire

asked on

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!
Avatar of nonubik
nonubik

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.
Avatar of Dirk Haest
If you need so much or or or ..

Perhaps better:
Select Case YourField
   Case 1, 2, ...
    Case 555, 66 ...
   case else
end select
Avatar of helphire

ASKER

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?
I think the If length is bounded by a maximum line length, if any. This should be in the help.
ASKER CERTIFIED SOLUTION
Avatar of joboy
joboy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
why do you say "this is the way it is being done "?  BY whom?

AW
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.
Hi,

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.

Regards,
Sibish.K.Abraham