Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Recreating the 'Show Possibilities As You type' effect
Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
GlobeTrotter




PostPosted: Mon Jun 20, 2005 8:17 pm   Post subject: 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.

VisualBASIC:

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 <= Len(stInput) Then
        txtTextBox.SelLength = iCursorLength
    End If
   
End Sub



I would appreciate any help, please.
Sponsor
Sponsor
Sponsor
sponsor
GlobeTrotter




PostPosted: Tue Aug 16, 2005 10:54 pm   Post subject: (No subject)

Could I please have some help, this has been here for a while and has only gotten 9 views!
[Gandalf]




PostPosted: Wed Aug 17, 2005 4:34 pm   Post subject: (No subject)

Sorry, but I can't help since I don't have any VB knowledge. The problem is that not too many people here VB here...

Maybe try detecting the length of the text continuously, and when there is less characters than there was previously you know that the user has deleted some text.
Tony




PostPosted: Thu Aug 18, 2005 9:29 am   Post subject: (No subject)

Well you could keep track of the cursor's position. If it suddenly goes to the left instead of expected right, the user must have backspaced a letter (or just clicked somewhere else)
[Gandalf]




PostPosted: Thu Aug 18, 2005 12:35 pm   Post subject: (No subject)

Yep, that's why I chose to detect the amount of letters in the string (or whatever it is) instead. When there are less than there were previously, you know for sure that the user deleted a letter.
wtd




PostPosted: Sat Aug 27, 2005 1:44 am   Post subject: (No subject)

If you're using VB.NET, I strongly suggest you ditch VB and use C#. Seriously. You'll thank me.
Display posts from previous:   
   Index -> Programming, Visual Basic and Other Basics -> Visual Basic Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: