text selection..

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jinDoankz
    New Member
    • Sep 2007
    • 5

    text selection..

    hi there..
    this my first post in this forum, hope you all can help me :)

    here the case:
    as the user is typing, i wants to capture the word which has just finished being typed -- as signalled when the user presses the space bar.

    i.e:
    the user type "thisword " (with space), then my program will capture "thisword"(with out space) when the user press the space bar.

    i use a rich text box object.

    need your suggestion..
    thanks
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    Write this code in LostFocus event of the RichTextBox:

    RTextBox1.Text = Trim(RTextBox1. Text)

    Regards
    Veena

    Comment

    • jinDoankz
      New Member
      • Sep 2007
      • 5

      #3
      text selection

      hi veena, thanks for the help..
      but your code is not work and didn't give any result to me.

      maybe you isn't too clear with what i want, here i explain a bit better:
      i have made a simple text editor using a richtextbox object, i need to capture the word which has just finished being typed when the user presses the space bar.

      example:
      if i type "wordOne " in the RtextBox, my program will capture "wordOne"an d do something with that word. when i continue and type "wordTwo " after the "wordOne" word (it's going to be "wordOne wordTwo "), my program will only capture the "wordTwo" word, and so on.

      the points is, how to get 1 word on the cursor left side.

      any idea for me?? :)
      Last edited by jinDoankz; Sep 29 '07, 02:10 AM. Reason: add some text

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        Yes, Your problem was not explained clear..
        any way Write This Code in KeyPress Event of the RichTextBox:

        This code is for TextBox, change it to rich text box..

        [code=vb]
        Private Sub Text1_KeyPress( KeyAscii As Integer)
        Dim i As Long
        Dim NewWord As String
        If KeyAscii = vbKeySpace Then
        NewWord = ""
        If Trim(Text1.text ) <> "" Then
        For i = Len(Text1.text) To 1 Step -1
        NewWord = Mid(Text1.text, i)
        If Mid(Text1.text, i, 1) = " " Then
        Exit For
        End If
        Next
        End If
        Label3.Caption = NewWord
        MsgBox NewWord
        End If
        End Sub
        [/code]


        Regards
        Veena

        Comment

        • jinDoankz
          New Member
          • Sep 2007
          • 5

          #5
          looks like your code will be work :) thanks..

          as i read your code, it will return the last word in richtextbox (sory if i'm wrong ;p).

          now, how if we want to capture the word based on cursor position.
          here the case:

          "one two three four five
          six seven eight nine
          ten(cursor here)"
          it will return "ten".

          now:
          "one two three four five
          six seven (cursor here)eight nine
          ten"
          it will return "seven".

          once again:
          "one(cursor here) two three four five
          six seven eight nine
          ten"
          it will return "one".

          still signalled by presses the space bar.

          thanks any way :)

          Comment

          • jinDoankz
            New Member
            • Sep 2007
            • 5

            #6
            text selection

            hi veena,

            my problem solved now :)
            i try to combine your last code with 2 others code
            and it's works :D

            thanks for the help..
            Last edited by jinDoankz; Oct 6 '07, 03:03 AM. Reason: add icon

            Comment

            Working...