Results 1 to 8 of 8

Thread: NEED HELP

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 1999
    Posts
    204
    is there a way when you press like a in a text box you can go to the a's in the combo box ex

    user :

    Hel
    combobox: hello

    is there a way to do this in vb

    WHat would we do with out Microsoft.
    A lot more.

  2. #2
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    I remember denniswrenn answered this a while ago, I'll show him this post for ya

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 1999
    Posts
    204
    thank you
    WHat would we do with out Microsoft.
    A lot more.

  4. #4
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    It seems to be something simple. I'm throwing together a sample and I'll post it when I'm done.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Jan 1999
    Posts
    204
    how do i use the ShellExecute to open a html page thanks
    WHat would we do with out Microsoft.
    A lot more.

  6. #6
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    Here's a sample that does what you asked about. I could have done a binary search function, but then I realized it would be simpler to build a string from the first letter of the combobox contents and use InStr instead. Paste this into a project with a combobox (Combo1) and a textbox (Text1). Remember to set the Sorted property of the combobox to True in the Properties window before you run this, or it won't work correctly.
    Code:
    Option Explicit
     
    Private Sub Form_Load()
     
       'some test things
       Combo1.AddItem "apple"
       Combo1.AddItem "aardvark"
       Combo1.AddItem "banana"
       Combo1.AddItem "ball"
       Combo1.AddItem "cherry"
       Combo1.AddItem "doorknob"
       Combo1.AddItem "eggplant"
       Combo1.AddItem "easy"
       Combo1.AddItem "test"
       Combo1.AddItem "fruit"
     
    End Sub
     
    Private Function Find(Target As ComboBox, SearchKey As String) As Integer
     
       Dim SearchDomain As String
       Dim Position As Integer
       Dim i As Integer
     
       SearchDomain = ""
       SearchKey = LCase$(SearchKey)    'remove case-sensitivity
       Find = -1                        'default is not finding anything
       
       'if there's nothing in the combobox, leave function
       If Target.ListCount = 0 Then Exit Function
     
       'cycle through all items in the combobox, building a
       'string using the first char of each item
       For i = 0 To (Target.ListCount - 1)
          SearchDomain = SearchDomain & LCase$(Left$(Target.List(i), 1))
       Next i
    
       'look for the first position of the desired key in the string
       Position = InStr(SearchDomain, SearchKey)
       
       'if it was found, return the position in the combobox corresponding
       'to the found position (items in a combobox go from 0 to ComboBox.ListCount-1
       If Position > 0 Then Find = Position - 1
     
    End Function
     
    Private Sub Text1_KeyPress(KeyAscii As Integer)
     
       Dim NewIndex As Integer
     
       'try to find the pressed key in the combobox
       NewIndex = Find(Combo1, Chr$(KeyAscii))
     
       'if found, change the combobox's currently selected index and text to show it
       If NewIndex <> -1 Then
          Combo1.ListIndex = NewIndex
          Combo1.Text = Combo1.List(Combo1.ListIndex)
       End If
     
    End Sub
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

  7. #7
    Frenzied Member
    Join Date
    Jul 1999
    Posts
    1,800
    Aw man! InStr! I tried making a sample for ya on my own (failed) and I tried Left (what was I thinking!) apparently dennis hasn't been on yet...oh well

  8. #8
    Fanatic Member Kaverin's Avatar
    Join Date
    Oct 2000
    Posts
    930
    Yeah, I almost smacked myself when I realized I could make VB do the hard work. I was trying to make a binary search function, but had no success. I couldn't recall how to make the search thing drop into the "lower" half of the set, and of course that's 50% of the whole algorithm heh heh.
    I'm baaaack...
    VB5 Professional Edition, VC++ 6
    Using a 1 gHz Thunderbird, 256 mb RAM, 40 gb HD system with Win98se

    I feel special because I finally figured out how to loop midis: Post link
    I'm a fanatic too

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width