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

x
?
Solved

IIF question

Posted on 2007-07-20
2
Medium Priority
?
167 Views
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?
0
Comment
Question by:Takamine334
2 Comments
 
LVL 81

Accepted Solution

by:
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)
Else
   xCommentCount = "None Found!"
End If

Kevin
0
 

Author Comment

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

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