Gets the ListIndex number from given Text in given ComboBox with starting and ending position speci
Gets the ListIndex number from given Text in given ComboBox with starting and ending position specified
Rate Gets the ListIndex number from given Text in given ComboBox with starting and ending position speci
(1(1 Vote))
'and ending to given values for any ComboBox
'IN: cb > ComboBox from which index is to be searched
' sTxt > Text to search in ComboBox
' lStart > Starting position (0 = From First)
' lEnd > Ending position (<0 is ComboBox.ListCount)
'OUT: lIDReturn > The ListIndex value which was found
'Return: True for success else False
'Tip: If Return is False and lIDReturn <> -1 Then lIDReturn
' is the error number, so that you can display error
' message later on if you wish.
Public Function IndexFromText( _
cb As ComboBox, sTxt As String, _
lIDReturn As Long, lStart As Long, _
lEnd As Long) As Boolean
'Handle the error to avoid illegal termination of program
On Error GoTo errIFT
'Variable declaration
Dim l As Long, lBegin As Long, lFinish As Long
Dim sItem As String, lCurID As Long
Dim lStep As Long, lCount As Long
'Initialization
IndexFromText = False
lIDReturn = -1
lBegin = lStart: lFinish = lEnd
lCount = cb.ListCount - 1
'Validating starting and ending position
If lBegin < 0 Then lBegin = 0
If lFinish > lCount Then lFinish = lCount
If lFinish < 0 Then lFinish = lCount
'Priority-wise
If lBegin > lFinish Then lStep = -1 Else lStep = 1
'Loop for verification
l = 0
For l = lBegin To lFinish Step lStep
sItem = cb.List(l)
If sItem = sTxt Then
IndexFromText = True
lIDReturn = l
Exit Function
End If
Next l
Exit Function
'Reply the error and failure both at a time
errIFT:
lRetVal = Err.Number
IndexFromText = False
Err.Clear
Exit Function
End Function
Gets the ListIndex number from given Text in given ComboBox with starting and ending position speci Comments
No comments yet — be the first to post one!
Post a Comment