
-----------------------------------
GlobeTrotter
Mon Jun 20, 2005 8:17 pm

Recreating the 'Show Possibilities As You type' effect
-----------------------------------
This is trying to recreate the effect, when you, are given possibilities as you type, in the form of hilighted text.  I wrote a procedure to do so, and it is called in the text_change event, but the problem is that the user can't use the delete/backspace key when it's is in use.  

I realize the problem is that it is assigning the hilighted text after you press delete, so I need a way of recognizing when the user has deleted text, so that the procedure won't be called when it has been.

This is the procedure, you input the textbox name and the sorted array of string possibilities.  Call it in the text_change event.


Private Sub ShowPossiblesAsTyped(ByRef txtTextBox As TextBox, aryStrings() As String)
    '--------------------------------------
    'Sub program:        ShowPossiblesAsTyped
    'Date Written:       June 20, 2005
    'Purpose:            Show a hilighted version of the possible string similar to what
    '                    they type, as they type
    'Input:              Text from the textbox we're working with
    'Output:             Hilighted possibility to the end
    'Sub program Input : Textbox to work with, array of strings
    'Sub program Output: none
    '--------------------------------------
    
    'Note: the inputted array must be sorted
    
    Dim iCount As Integer
    Dim iCount2 As Integer
    Dim iCursorStart As Integer 'Where the cursor/blinking line/ is
    Dim iCursorLength As Integer
    Dim stInput As String 'The string in the textbox
    Dim stSameString As String
    Dim iTempSameCount As Integer
    
    'Assign the cursor, and the input text
    iCursorStart = txtTextBox.SelStart
    stInput = txtTextBox.Text
    
    For iCount = 0 To UBound(aryStrings)
        If InStr(UCase(aryStrings(iCount)), UCase(stInput)) Then
            For iCount2 = 1 To Len(stInput)
                If Mid(UCase(aryStrings(iCount)), iCount2, 1) = Mid(UCase(stInput), iCount2, 1) Then
                    iTempSameCount = iTempSameCount + 1
                Else
                    iCount2 = Len(stInput)
                End If
            Next iCount2
            If iTempSameCount > 0 Then
                stInput = aryStrings(iCount)
                stSameString = aryStrings(iCount) 'Since we end the loop, we need a variable
                                                  'to work with outside the loop
                iCount = UBound(aryStrings) 'End the loop
            Else
                iTempSameCount = 0
            End If
        End If
    Next iCount
        
    'iCursorStart = iTempSameCount
    iCursorLength = Len(stSameString) - iTempSameCount
    
    'Assign the changed text
    txtTextBox.Text = stInput
    
    'To ensure no errors, make sure the cursor position is valid, then assign it
    If iCursorStart >= 0 Then
        txtTextBox.SelStart = iCursorStart
    End If
    If iCursorStart + iCursorLength 