Hello CodeCall members ..
Today I am going to show you how to make a simple SearchList using VB 6 ..![]()
Ok .. all you need is a form .. a TextBox .. a button and a ListBox ..
the SearchList will look like this:
Ok than .. rename the button to "Search" first ..
and than add this code to the button ..
and than after this .. add:Code:Dim theList As Long Dim textToSearch As String Dim theListText As String textToSearch = LCase(Text1.Text) For theList = 0 To List1.ListCount - 1 theListText = LCase(List1.List(theList)) If theListText = textToSearch Then List1.Text = textToSearch Next End Sub
this is the list that loads the items to the listbox on Application StartUp ..Code:Private Sub Form_Load() List1.AddItem "Code" List1.AddItem "CodeCall" List1.AddItem "Member" List1.AddItem "Admin" List1.AddItem "Mod" End Sub
now .. if you search for one the items on the list ..that item will be selected ..
...
and now .. a test ..
Thanks, Egz0N ..![]()
Last edited by Jordan; 01-15-2009 at 06:44 AM.
Not bad, it is mostly code so I'm left with a few questions (being a n00b). How does this work? How does the search list know how to find the results? How do I remove items from the listbox? What does this code do?
Why do you use a for loop?Code:theListText = LCase(List1.List(theList))
Why do you compare the text values?Code:For theList = 0 To List1.ListCount - 1
??Code:If theListText = textToSearch Then List1.Text = textToSearch![]()
I Really needed it..
Thank a lot EgzON +rep .
this works using a loop that passes through each item on the listbox and checks if the searched item fits with the found one ..How does this work?
by checking all the elements of the list one by one if they are the same as the text we typed in the textbox ..How does the search list know how to find the results?
using the code list1.removeitem(index)How do I remove items from the listbox?
it takes only lowercase words on the list with index "thelist"What does this code do?
Code:theListText = LCase(List1.List(theList))
cos "for loop" is more adapted for this searchlist ..Why do you use a for loop?
Code:For theList = 0 To List1.ListCount - 1
this code is used to check if the current element is the same as the searched words if yes, the searched item will be selected ..Why do you compare the text values?
Code:If theListText = textToSearch Then List1.Text = textToSearch
sry .. i didn't explain this from the beginning but next time i'll explain each of the code what it does ..
Thanks, Egz0N![]()
Perfect! Now I understand!+rep
Looked up, looks really good !
One question how did you do it good??
+rock. Very nice
![]()
Interested in participating in community events?
Want to harness your programming skill and turn it into absolute prowess?
Come join our programming events!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks