Results 1 to 10 of 10

Thread: Combo Box Autocomplete problem

  1. #1

    Thread Starter
    Member psychofoo's Avatar
    Join Date
    Jun 2005
    Posts
    48

    Combo Box Autocomplete problem

    hi!

    can someone help me how to convert this code to public function... this code works but the problem is i have to copy it in every combo box command. here's the code
    VB Code:
    1. Option Explicit
    2.  
    3. Dim InChangeMode As Boolean
    4. Dim BackSpacePressed As Boolean
    5.  
    6. Private Sub Combo1_Change()
    7. On Error Resume Next
    8. Dim idx As Integer
    9. Dim SelFrom As Integer
    10.  
    11. If InChangeMode Then Exit Sub
    12. If BackSpacePressed Then
    13. BackSpacePressed = False
    14. Exit Sub
    15. End If
    16.  
    17. With Combo1
    18. If Trim(.Text) = "" Then Exit Sub
    19. If .ListCount < 0 Then Exit Sub
    20. InChangeMode = True
    21. For idx = 0 To .ListCount
    22. If UCase(.Text) = UCase(Left(.list(idx), Len(.Text))) Then Exit For
    23.  
    24. '' If your data in Combox is sorted than add the next line
    25. ' If UCase(.Text) < UCase(Left(.List(idx), Len(.Text))) Then GoTo EndOfProcess
    26.  
    27. Next idx
    28. If idx < .ListCount Then
    29. SelFrom = Len(.Text)
    30. .ListIndex = idx
    31. .SelStart = SelFrom
    32. .SelLength = Len(.Text) - SelFrom
    33. End If
    34. End With
    35. EndOfProcess:
    36. InChangeMode = False
    37. End Sub
    38.  
    39. Private Sub Combo1_KeyPress(KeyAscii As Integer)
    40. Select Case KeyAscii
    41. Case vbKeyBack
    42. BackSpacePressed = True
    43. End Select
    44.  
    45. End Sub
    46.  
    47. Private Sub Form_Load()
    48. 'Dim idx
    49.  
    50. 'With Combo1
    51. '.Clear
    52. 'For idx = 65 To 88
    53. '.AddItem Chr(idx) & Chr(idx + 1) & Chr(idx + 2) & "test"
    54. 'Next idx
    55. 'End With
    56. InChangeMode = False
    57. BackSpacePressed = False
    58. End Sub


    thanx for the help!

  2. #2
    Fanatic Member
    Join Date
    Aug 2004
    Location
    Essex, UK
    Posts
    774

    Re: Combo Box Autocomplete problem

    I'm not sure what you mean by "every combo box command". If you want to use the same code for many combo boxes on the same form then you can create a control array. The structure will look like this:
    VB Code:
    1. Private Sub Combo1_Change(Index As Integer)
    2.  
    3.     With Combo1(Index)
    4.  
    5.     ' your code in here...
    6.  
    7.     End With
    8.  
    9. End Sub
    10.  
    11. Private Sub Combo1_KeyPress(Index As Integer, KeyAscii As Integer)
    12.  
    13.     ' more of your code in here...
    14.  
    15. End Sub
    Note sure if that's what you need....

  3. #3

    Thread Starter
    Member psychofoo's Avatar
    Join Date
    Jun 2005
    Posts
    48

    Re: Combo Box Autocomplete problem

    hi, thanx for d reply but wat i mean for every combo box command is i will not put dat code in every combo1_change() , combo2_change() etc... i can access it publicly so dat every combo box in my form has autocomplete.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Combo Box Autocomplete problem

    That's not possible with a self-contained function. You would need to make an AutoComplete class and then declare a separate class for each combo box. If you want to do it that way I can try an example for ya

  5. #5

    Thread Starter
    Member psychofoo's Avatar
    Join Date
    Jun 2005
    Posts
    48

    Re: Combo Box Autocomplete problem

    I dnt knw how to make classes... can u make 1 for me.. thanx!

  6. #6
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Combo Box Autocomplete problem

    Quote Originally Posted by psychofoo
    I dnt knw how to make classes... can u make 1 for me.. thanx!
    t3h LOL!

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  7. #7
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Combo Box Autocomplete problem

    Sorry, but there aren't many people who'll just create a class for you. Besides, wouldn't it be more fun to learn how to do it rather than get away with it being done for you? It's really not that hard at all. Try searching google, or the forums. Once you get the hang of them, they'll become part of nearly every program you write.

    @The Rest of us:
    I think it's time we covered some of the stuff like API's, Classes, Etc. Unless there are some pretty easy to understand ones already on the forums?

    chem

    Visual Studio 6, Visual Studio.NET 2005, MASM

  8. #8

    Thread Starter
    Member psychofoo's Avatar
    Join Date
    Jun 2005
    Posts
    48

    Re: Combo Box Autocomplete problem

    Quote Originally Posted by penagate
    That's not possible with a self-contained function. You would need to make an AutoComplete class and then declare a separate class for each combo box. If you want to do it that way I can try an example for ya
    I guess he will make an example for me :P

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Combo Box Autocomplete problem

    Here it is, might have a few bugs but it seems to work.

    BTW, I don't usually just write code for people, but in this case it was an example that I already had (part of it anyway) I just wrapped it in a class to show you how it is done. Hopefully you learn something from it for the future

    Attached Files Attached Files

  10. #10

    Thread Starter
    Member psychofoo's Avatar
    Join Date
    Jun 2005
    Posts
    48

    Re: Combo Box Autocomplete problem

    thanx!

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