VB 6.0 - WordWheel required

Hello there,

could anyone help me with some VB 6 code
for a wordwheel. eg. I need to be able to check for names in a list, where the highlight will jump to the first matching name in alphabetical order ...

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

"HOWTO: Search a ListBox Control Quickly"


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial

for this example create a form:
- and add 1 TextBox (named: s_box) ... search box
- and add 1 ListBox  (named: Dictionary) ... where all your names will reside (populate this from a DB)

in your code : General/Declarations paste the following code:

========> cut here <==============

Private Sub s_box_KeyUp(KeyCode As Integer, Shift As Integer)

Dim cntr1 As Integer 'counter 1
Dim cntr2 As Integer 'counter 2
Dim n_str As String 'new string

' perform the search
n_str = s_box.Text
For cntr1 = 0 To Dictionary.ListCount - 1)
If Len(n_str) <= Len(Dictionary.List(cntr1)) Then
If UCase(Left(n_str, Len(n_str))) = _
            UCase(Left(Dictionary.List(cntr1), Len(n_str))) And _
Len(n_str) <> 0 Then
  Dictionary.Selected(cntr1) = True
  cntr1 = Dictionary.ListCount - 1
End If
If cntr1 < Dictionary.ListCount - 1 Then
   cntr1 = cntr1 + 1
End If
End If
Next cntr1

End Sub

========> cut here <==============

Hope this helps,
jarrod100Author Commented:
10x guys,

   both codes seem to work fine:
    - Erick37s' code is shorter :)
    - runner75's code helps me
      understand how the search
      is accomplished.

   you both deserve 100 points,
   however this time Erick37 was
   first :)

10x Erick37

Glad to help.  Thanks.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.