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


IIF question

Posted on 2007-07-20
Medium Priority
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

zorvek (Kevin Jones) earned 2000 total points
ID: 19535288
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

ID: 19535330
Well, that makes sense! Thank you :)

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses
Course of the Month18 days, 14 hours left to enroll

834 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