IIF question

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?
Who is Participating?
zorvek (Kevin Jones)ConsultantCommented:
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

Takamine334Author Commented:
Well, that makes sense! Thank you :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.