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

Posted on 2005-04-19
Last Modified: 2008-03-17
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!
Question by:helphire
    LVL 16

    Expert Comment

    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.
    LVL 53

    Expert Comment

    If you need so much or or or ..

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

    Author Comment

    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?
    LVL 6

    Expert Comment

    I think the If length is bounded by a maximum line length, if any. This should be in the help.
    LVL 5

    Accepted Solution

    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,
    LVL 44

    Expert Comment

    why do you say "this is the way it is being done "?  BY whom?

    LVL 6

    Expert Comment

    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.
    LVL 1

    Expert Comment


    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.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    This article is filled with multiple code samples and explanations for mathematical calculations. They are as follows: 1. General tips 2. Quadratic formula 3. Object collision 4. Projectile path General Tips       Here are some of my tips f…
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now