Highlighting characters in VB6 Textbox while typing itself....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rajeshnrh74
    New Member
    • Nov 2007
    • 4

    Highlighting characters in VB6 Textbox while typing itself....

    Hi Gurus,
    I need one solution
    I'm using VB6, one of its Form contains a TextBox
    What i need is whatever characters I type in it that
    should be highlighted
    ex

    First when I type "a" -> "a" should be selected
    second when I type "b" -> "ab" should be selected
    third when I type "c" -> "abc" should be selected
    fourth when I type "d" -> "abcd" should be selected
    likewise it go.

    ie overall characters upto the cursor end should be selected.

    Help me out.
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    To Highlight Text in a Textbox, you can use this code:

    [code=vb]
    Text1.SelStart =0
    Text1.SelLength = Len(Text1.Text)
    [/code]

    Write this in Got_Focus Event.
    If you write this in Change Event (as per your Requirement),
    The Highlighted Text would keep on deleting with every key typed..
    Not very sure, why do you have such a requirement...

    Regards
    Veena

    Comment

    • rajeshnrh74
      New Member
      • Nov 2007
      • 4

      #3
      Veena,
      Thnks for your response.
      Actually my work behind reading Barcode thru Barcode Reader into the
      TextBox, The Maxlength of the TextBox is 12.
      If I Input some characters manually into the TextBox Say "abc" (without quotes)
      now the cursor is in 4th place from there it won't allow Barcode Reader to read.
      It should start from 1st place only by erasing already existing 3 characters.
      This is my situation.

      Can U come out of this.

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        Then, write the code (my previous post) in got_focus event, I think it would solve your problem..

        Regards
        Veena

        Comment

        • dontbe
          New Member
          • Nov 2007
          • 3

          #5
          Hi,

          Maybe You can add this code on Change event in your textbox
          Code:
          Dim ChrSet As String, chrpos As Integer, getchr As String
          ChrSet = Text1.Text
          If IsNumeric(ChrSet) = False Then
              If Len(ChrSet) <> 0 Then
                  chrpos = InStr(1, ChrSet, Right(ChrSet, 1), vbTextCompare)
                  getchr = Right(ChrSet, 1)
                  Text1.SelStart = chrpos - 1
                  Text1.SelLength = Len(getchr)
              End If
          End If
          This Code Will Highlight the last character, and you replaced it with the right for for you card reader!

          Comment

          Working...