?
Solved

Autofill a textbox in VB6

Posted on 2003-04-01
5
Medium Priority
?
1,118 Views
Last Modified: 2012-06-21
We have all seen (well at least those who have graduated to the Nineties with Win2000 and up) the "autofill" features in text boxes.  Most notably one finds them in Outlook, where you can begin typing an email address or contact name and if you have sent to that person before, Outlook gives you a list of previous entries that you can choose from.

Does anyone know how to implement this?

I have seen code snippets out there but they are almost all combobox-related.  I'd like something that works just like in Outlook, with the textbox dropping down into a mini listbox with no UI around it.

Capisce?

Please help me.  <wink>

John
0
Comment
Question by:JXCovert
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 8247267
0
 

Author Comment

by:JXCovert
ID: 8248136
That is good stuff but I don't want URLs or drives....

I need to be able to draw from my own list in effect.
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 2000 total points
ID: 8248219
0
 

Expert Comment

by:tinkledoomhammer
ID: 8250079
It is essentially the same whether you use an edit box or any other control.
If your control doesn't maintain a list for you, you have to do it yourself. A simple linked list is ideal. Initially it contains all previously entered data.
With each keystroke, you search through the list, and delete any inappropriate entries. That does mean that you have to handle keystrokes.

Filling in the text is simple... just replace it with SetWindowText and move the cursor.

I can't give you an example because i don't do vb. If you _want_ one in c++ i could make one, though.
0
 
LVL 12

Expert Comment

by:jyokum
ID: 8251365
here's an example:
setup a form and add a combo box (Combo1)
paste in the following...

Option Explicit

#If Win32 Then

   Private Declare Function SendMessage Lib "user32" Alias _
       "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
       ByVal wParam As Long, lParam As Long) As Long

#Else

   Private Declare Function SendMessage Lib "User" ( _
       ByVal hwnd As Integer, ByVal wMsg As Integer, _
       ByVal wParam As Integer, lParam As Any) As Long

#End If

Private Const WM_SETREDRAW = &HB
Private msOldString As String ' module level global
Private miStart As Integer    ' module level global
Private miLength As Integer   ' module level global

 Private Sub Combo1_KeyUp(KeyCode As Integer, Shift As Integer)
    Dim sComboText As String
    Dim iLoop As Integer
    Dim sTempString As String
    Dim lReturn As Long
    Dim bInList As Boolean
    Dim sItem
   
  If Not KeyCode = Asc(vbTab) And Not KeyCode = vbKeyShift And _
      Not KeyCode = vbKeyLeft And Not KeyCode = vbKeyRight And _
      Not KeyCode = vbKeyHome And Not KeyCode = vbKeyEnd Then
       
        bInList = False
       
        With Combo1
            sTempString = .Text
            If Len(sTempString) = 1 Then sComboText = sTempString
            lReturn = SendMessage(.hwnd, WM_SETREDRAW, False, 0&)
            For iLoop = 0 To (.ListCount - 1)
                sItem = .List(iLoop)
                If UCase((sTempString & Mid$(sItem, _
                 Len(sTempString) + 1))) = UCase(sItem) Then
                    .ListIndex = iLoop
                    .Text = sItem
                    msOldString = sItem
                    miStart = Len(sTempString)
                    .SelStart = miStart
                    miLength = Len(sItem) - (Len(sTempString))
                    .SelLength = miLength
                    sComboText = sComboText & Mid$(sTempString, _
                        Len(sComboText) + 1)
                    bInList = True
                    Exit For
                End If
            Next iLoop
           
            If Not bInList Then
                .Text = msOldString
                .SelStart = miStart
                .SelLength = miLength
            End If
           
            lReturn = SendMessage(.hwnd, WM_SETREDRAW, True, 0&)
        End With
    End If
   End Sub

Private Sub Form_Load()
 'JUST SAMPLE FOR DEMO PURPOSES
 'YOU CAN OBVIOUSLY ADD WHAT YOU NEED
 'TO ADD HERE
    With Combo1
        .AddItem "Blue"
        .AddItem "Green"
        .AddItem "Yellow"
       
        .ListIndex = 0
        .Text = .List(0)
        .SelStart = 0
        .SelLength = Len(.Text)
        msOldString = .Text
        miStart = 0
        miLength = .SelLength
    End With
End Sub


0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Six Sigma Control Plans
Progress
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question