我继承了一个 ASP 项目,我是一个没有 ASP 知识的 PHP 编码器。对不起,如果这篇文章很长,我只想提供尽可能多的信息。
我正在为这一块代码而苦苦挣扎。
Dim resultArray As String()
For Each resultitem In resultArray
' Do something with each element of the array
hash.Add(dllFunctionObj.ReturnTemplateField(i), resultitem)
i = i + 1
Next
错误:
Exception!!: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
解决方案似乎很简单。检查是否resultitem
为空,然后中断或跳到下一个元素。
所以我尝试了这个:
If IsNull(resultitem) Then
Break
End If
错误:
BC30451: Name 'IsNull' is not declared.
我尝试了在网上找到的其他几种替代方法:
IsEmpty(resultitem)
- IsEmpty 未声明String.IsNullOrEmpty(resultitem)
- 索引越界错误,似乎没有效果resultitem Is Nothing
- 索引超出范围Not (Len(resultitem) > 0)
- 索引超出范围Len(resultitem) = 0
- 出界索引
唯一似乎接近的是:
If Not resultitem Then
Break
End If
错误:
Exception!!: Conversion from string "some_string_here" to type 'Long' is not valid.
如果我使用Next
而不是Break
我得到这个错误:
If Not resultitem Then
Next
End If
错误:
BC30081: 'If' must end with a matching 'End If'.
帮助!
我将包含完整的代码块以防万一
Dim isResultArray As Boolean
isResultArray = methodInf.ReturnType.IsArray()
If isResultArray Then
Dim resultArray As String()
'*** Invoke the dll function
resultArray = methodInf.Invoke(REMem, args.ToArray)
Dim i As Integer = 0
For Each resultitem In resultArray
If Not resultitem Then
Response.Write("Found null value.")
Exit For
End If
Response.Write("i: " & i & "<br />")
hash.Add(dllFunctionObj.ReturnTemplateField(i), resultitem)
i = i + 1
' i = 6 will cause Get Constituent Name to work
'If i = 6 Then
' Exit For
'End If
Next
outputArray.Add(hash)
Else
'*** could be boolean, string, long etc.
Dim result As String
'*** Invoke the dll function
result = methodInf.Invoke(REMem, args.ToArray)
hash.Add(dllFunctionObj.ReturnTemplateField(0), result)
outputArray.Add(hash)
End If