P.T.A.M. Administrator

Joined: 08 Oct 2003 Posts: 752 Location: Greece
|
Posted: Oct 10th, 2003 08:13 AM Post subject: Search in combobox or listbox for a string, non API way |
|
|
| Code: | Option Explicit
Private Sub Command1_Click()
FindCB Combo1, Text1.Text
End Sub
Private Sub Command2_Click()
FindLB List1, Text1.Text
End Sub
Private Sub Form_Load()
Command1.Caption = "Find in Combo Box"
Command2.Caption = "Find in List Box"
Combo1.AddItem "one"
Combo1.AddItem "two"
Combo1.AddItem "three"
Combo1.AddItem "four"
Combo1.AddItem "five"
Combo1.AddItem "six"
Combo1.AddItem "seven"
List1.AddItem "one"
List1.AddItem "two"
List1.AddItem "three"
List1.AddItem "four"
List1.AddItem "five"
List1.AddItem "six"
List1.AddItem "seven"
End Sub
Private Sub FindLB(LB As ListBox, TextToFind As String, CaseSensitive As Boolean)
Dim i As Integer
For i = 0 To LB.ListCount - 1
If CaseSensitive = True Then
If TextToFind = LB.List(i) Then
LB.ListIndex = i
End If
Else
If LCase(TextToFind) = LCase(LB.List(i)) Then
LB.ListIndex = i
End If
End If
Next
End Sub
Private Sub FindCB(CB As ComboBox, TextToFind As String, CaseSensitive As Boolean)
Dim i As Integer
For i = 0 To CB.ListCount - 1
If CaseSensitive = True Then
If TextToFind = CB.List(i) Then
CB.ListIndex = i
End If
Else
If LCase(TextToFind) = LCase(CB.List(i)) Then
CB.ListIndex = i
End If
End If
Next
End Sub |
_________________ No one is completely useless. They can at least be an example of what to avoid. |
|