by Jonathan Templer (1 Submission)
Category: Windows System Services
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Fri 4th June 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)
This code will search for a specific word in a listbox. It will return the specific entry in the listbox containing the target word.
API Declarations
Dim X, y, z As Byte
Dim Result, LResult As String
'a button named command1
'a listbox named lstResults
'and sit back and enjoy my blood, sweat and tears!
Private Sub Command1_Click()
Screen.MousePointer = 11
X = 0
y = 0
lstResults.Clear
For z = 1 To Form1!lstsource.ListCount
Result = ""
LResult = ""
For i = 0 To Len(Form1!lstsource.List(y))
Car(i) = Mid(Form1!lstsource.List(y), i + 1, 1)
If Car(i) = " " Then
X = i + 1
Exit For
Else
Result = Result & Car(i)
If i = 0 Then
LResult = LResult & LCase(Car(i))
Else
LResult = LResult & Car(i)
End If
End If
Next i
If Result = txtSearchText.Text Or LResult = txtSearchText.Text Then
lstResults.AddItem Form1!lstsource.List(y)
y = y + 1
Else
11:
LResult = ""
Result = ""
For i = X To Len(Form1!lstsource.List(y))
Car(i) = Mid(Form1!lstsource.List(y), i + 1, 1)
If Car(i) = " " Then
X = i
Exit For
Else
Result = Result & Car(i)
If i = X Then
LResult = LResult & LCase(Car(i))
Else
LResult = LResult & Car(i)
End If
End If
Next i
If Result = "" Then
y = y + 1
GoTo 12
End If
If Result = txtSearchText.Text Or LResult = txtSearchText.Text Then
lstResults.AddItem Form1!lstsource.List(y)
y = y + 1
Else
GoTo 10
End If
End If
12:
Next z
txtSearchText.SelStart = 0
txtSearchText.SelLength = Len(txtSearchText.Text)
If lstResults.ListCount = 0 Then
MsgBox "No records were found for" & Chr(34) & txtSearchText.Text & Chr(34), vbExclamation, "Search Result"
End If
Screen.MousePointer = 0
Exit Sub
10:
X = X + 1
GoTo 11:
End Sub
Private Sub Form_Load()
Me.Controls.Add "vb.listbox", "lstsource", Form1
With Form1!lstsource
.AddItem "Good Morning"
.AddItem "Good Bye"
.AddItem "Good Night"
End With
End Sub
No comments have been posted about This code will search for a specific word in a listbox. It will return the specific entry in the li. Why not be the first to post a comment about This code will search for a specific word in a listbox. It will return the specific entry in the li.