Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
 
 
 
500MB 27GB Web Hosting - $9.95/Month
 
 
 
 
 
Old Pages
 
Old Index
Site Map
What's New
 
Books
How To
Tips & Tricks
Tutorials
Stories
Performance
Essays
Links
Q & A
New in VB6
Free Stuff
Pictures
 
 
 
TitleSee which word in a RichTextBox the user clicked
KeywordsRichTextBox, scroll, line, print, preview, click
CategoriesControls
 
In the control's Click event handler, use the SelStart property to see where the user clicked.
 
Private Sub RichTextBox1_Click()
Dim pos1 As Integer
Dim pos2 As Integer
Dim txt As String
Dim txtlen As Integer

    ' Find the beginning of the word.
    pos1 = RichTextBox1.SelStart
    txt = RichTextBox1.Text
    If pos1 > 1 Then
        Do While Mid$(txt, pos1, 1) <> " "
            pos1 = pos1 - 1
            If pos1 <= 1 Then Exit Do
        Loop
        If pos1 > 1 Then pos1 = pos1 + 1
    End If
    
    ' Find the end of the word.
    pos2 = pos1
    txtlen = Len(txt)
    Do While Mid$(txt, pos2, 1) <> " "
        pos2 = pos2 + 1
        If pos2 > txtlen Then Exit Do
    Loop
    If pos2 <= txtlen Then pos2 = pos2 - 1
    
    txt = Mid$(txt, pos1, pos2 - pos1 + 1)
    MsgBox txt
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated