0

当使用为 null 的元素调用 ArrayLen 时,它会引发错误。你如何让它返回0?

The value '' cannot be converted to a number.

The error occurred in D:/Resource/WWW/DEV/ww1dev.cwtvacations.com/welcome_survey/welcome_survey_question_builder.cfm: line 12

10 :    <cfset curPage = SESSION.thisPage />
11 : 
12 :    <cfloop from="1" to="#ArrayLen(SESSION.WHSurveyStruct.pagesQuestions[curPage])#" index="curQuestion">
13 :        <cfif (SESSION.WHSurveyStruct.pagesQuestions[curPage][curQuestion].SectionID eq 4 AND SESSION.WHSurveyStruct.AirlineID neq 0)   <!--- Ask airline questions, if airline known  --->
14 :                OR (SESSION.WHSurveyStruct.pagesQuestions[curPage][curQuestion].SectionID neq 4 
4

1 回答 1

0

您可以做几件事。您可以使用三元运算符并将整个事物分配给变量:

upperBound = isNull(SESSION.WHSurveyStruct.pagesQuestions[curPage]) ? 0 : ArrayLen(SESSION.WHSurveyStruct.pagesQuestions[curPage]);

或者你可以事先检查一下。但是,您将数组的特定元素指定为数组似乎很奇怪。即包含数组还是数组SESSION.WHSurveyStruct.pagesQuestions[curPage]pagesQuestions[]如果是数组,则删除[curParge]索引。

于 2012-05-30T23:42:38.753 回答