VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Auto Text generation..when you press a key the related text will appear in a textbox autotmatically

by milind/Clio (1 Submission)
Category: Windows API Call/Explanation
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sun 11th August 2002
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Auto Text generation..when you press a key the related text will appear in a textbox autotmatically

API Declarations


Dim i As Integer
Dim str As String





Private Const CB_FINDSTRING As Long = &H14C
Private Const CB_SHOWDROPDOWN As Long = &H14F


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

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


Rate Auto Text generation..when you press a key the related text will appear in a textbox autotmatically



   ByVal str As String, intKey As Integer, _
   Optional ctlTarget As Variant)
    Dim lngIdx As Long
    Dim FindString As String
    On Error Resume Next
    If (intKey < 32 Or intKey > 127) And _
       (Not (intKey = 13 Or intKey = 8)) Then Exit Sub
    
    If Not intKey = 13 Or intKey = 8 Then
        If Len(ctlSource.Text) = 0 Then
            FindString = str & Chr$(intKey)
        Else
            FindString = Left$(str, ctlSource.SelStart) & Chr$(intKey)
        End If
    End If
    
    If intKey = 8 Then
       If Len(ctlSource.Text) = 0 Then Exit Sub
       Dim numChars As Integer
       numChars = ctlSource.SelStart - 1
       'FindString = Left(str, numChars)
       If numChars > 0 Then FindString = Left(str, numChars)
        If numChars = -1 Then
            ctlSource = Mid(str, 1, Len(str) - 1)
            SendKeys "{END}"
        End If
    End If
    
    If IsMissing(ctlTarget) And (TypeName(ctlSource) = "ComboBox" Or TypeName(ctlSource) = "TextBox") Then
        Set ctlTarget = ctlSource
        If intKey = 13 Then
            Call SendMessageStr(ctlTarget.hwnd, _
                CB_SHOWDROPDOWN, True, 0&)
            Exit Sub
        End If
        lngIdx = SendMessageStr(ctlTarget.hwnd, CB_FINDSTRING, -1, FindString)
        If lngIdx <> -1 Then
                ctlTarget.ListIndex = lngIdx
                ctlSource.SelStart = Len(FindString)
                ctlSource.SelLength = Len(ctlSource.Text) - ctlSource.SelStart
                Text1.Text = Combo1.Text
                Text1.SelStart = Len(FindString)
                Text1.SelLength = Len(ctlSource.Text) - ctlSource.SelStart
        Else
                If intKey <> 8 Then
                ctlSource = Left(FindString, Len(FindString) - 1)
                SendKeys "{END}"
                End If
        End If
        intKey = 0
    Else
        Exit Sub
    End If
End Sub
'End

Private Sub Form_Load()
Combo1.AddItem "milind"
Combo1.AddItem "rajesh"
Combo1.AddItem "rajvrinda"
Combo1.AddItem "Shilpa"
Combo1.AddItem "shipla"
Combo1.AddItem "amit"
Combo1.AddItem "amin1"
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
Combo1.Text = Text1.Text
Call FindIndexStr(Combo1, Combo1.Text, KeyAscii)
End Sub


Download this snippet    Add to My Saved Code

Auto Text generation..when you press a key the related text will appear in a textbox autotmatically Comments

No comments have been posted about Auto Text generation..when you press a key the related text will appear in a textbox autotmatically. Why not be the first to post a comment about Auto Text generation..when you press a key the related text will appear in a textbox autotmatically.

Post your comment

Subject:
Message:
0/1000 characters