[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 538
  • Last Modified:

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!
1 Solution
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
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?
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

pritaeasSoftware EngineerCommented:
I think the If length is bounded by a maximum line length, if any. This should be in the help.
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,
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.


Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now