IIF question

Posted on 2007-07-20
Last Modified: 2010-04-09
Why am I getting a subscript out of range?

xCommentCount = IIf(Len(xCommentCount) > 0, Split(xCommentCount, ">")(2), "None Found!")

On some pages if len(xCommentCount) is greater than 0, then this works:
Split(xCommentCount, ">")(2)

But if len(xCommentCount) = 0, then obvously it wouldn't work, but shouldn't it then have "None Found!" as the value?

What am I doing wrong?
Question by:Takamine334
    LVL 81

    Accepted Solution

    You are assuming that there are array elements when there are none...IIF evaluates all parameters BEFORE evaluating the condition.

    Dim Tokens As Variant
    Tokens = Split(xCommentCount, ">")
    If UBound(Tokens) > 1 Then
       xCommentCount = Tokens(2)
       xCommentCount = "None Found!"
    End If


    Author Comment

    Well, that makes sense! Thank you :)

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Suggested Solutions

    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    This article describes how to create custom column layout styles for Bootstrap. The article uses 5 columns to illustrate the concept, but the principle can be extended to any number of columns.
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
    The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

    779 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

    12 Experts available now in Live!

    Get 1:1 Help Now