Guest User

Untitled

a guest
Apr 19th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.62 KB | None | 0 0
  1. Public Function FindCodeIndex(vArray As Variant, MatchValue As String) As Integer
  2. ''This function locates a value in a combo box returning the index or -1 if not found
  3. Dim lCount As Long
  4. Dim maxCount As Long
  5. Dim arrayStr As String
  6.  
  7.  
  8. On Error GoTo ErrorHandler
  9.  
  10. maxCount = UBound(vArray)
  11.  
  12.  
  13. For lCount = 0 To maxCount
  14. arrayStr = vArray(1, lCount)
  15.  
  16. If UCase$(arrayStr) = UCase$(MatchValue) Then
  17. FindCodeIndex = Int(lCount)
  18. Exit Function
  19. End If
  20. Next lCount
  21.  
  22. FindCodeIndex = -1
  23.  
  24. Exit Function
  25.  
  26.  
  27. ErrorHandler:
  28.  
  29. MsgBox "Unexpected error in frmComment::FindCodeIndex()" & vbCrLf & _
  30. "Error Code: " & CStr(Err.Number) & " Error Desc: " & Err.Description
  31.  
  32. Public Function FindCodeIndex(Array() As String, ByVal MatchValue As String) As Long
  33.  
  34. Dim index As Long
  35. Dim upper_bound As Long
  36.  
  37. upper_bound= UBound(Array)
  38. MatchValue = UCase(MatchValue)
  39.  
  40. For index = 0 To upper_bound
  41. If UCase(Array(index)) = MatchValue Then
  42. FindCodeIndex = index
  43. Exit Function
  44. End If
  45. Next index
  46.  
  47. FindCodeIndex = -1
  48.  
  49. End Function
  50.  
  51. Private Declare Function SendMessage Lib "User32.dll" Alias "SendMessageA" (ByVal hWnd As Long, ByVal uMsg As Long, ByRef wParam As Any, ByRef lParam As Any) As Long
  52.  
  53. Private Const CB_FINDSTRINGEXACT As Long = &H158
  54.  
  55. Public Function FindCodeIndex(ByRef cmb As ComboBox, ByRef sMatchValue As String) As Long
  56. 'This function locates a value in a combo box returning the index or -1 if not found
  57.  
  58. FindCodeIndex = SendMessage(cmb.hWnd, CB_FINDSTRINGEXACT, ByVal -1, ByVal sMatchValue
  59.  
  60. End Function
Add Comment
Please, Sign In to add comment