我一直试图找出为什么在下面的代码中,第三次通过循环我在评估“For lCount = 0 To maxCount”行时得到错误类型 13 不匹配。我最初认为问题在于从 vArray 中获取值,但测试表明它是由“For”行触发的。我不知道在循环处理过程中类型将如何变化。谢谢!
Public Function FindCodeIndex(vArray As Variant, MatchValue As String) As Integer
''This function locates a value in a combo box returning the index or -1 if not found
Dim lCount As Long
Dim maxCount As Long
Dim arrayStr As String
On Error GoTo ErrorHandler
maxCount = UBound(vArray)
For lCount = 0 To maxCount
arrayStr = vArray(1, lCount)
If UCase$(arrayStr) = UCase$(MatchValue) Then
FindCodeIndex = Int(lCount)
Exit Function
End If
Next lCount
FindCodeIndex = -1
Exit Function
ErrorHandler:
MsgBox "Unexpected error in frmComment::FindCodeIndex()" & vbCrLf & _
"Error Code: " & CStr(Err.Number) & " Error Desc: " & Err.Description