?
Solved

How to select  a sentence from a rich text box control  ?

Posted on 2002-06-07
6
Medium Priority
?
276 Views
Last Modified: 2006-11-17
In rich text box control i have some sentences. each sentences consist of 2 or 3 or 4 lines each. each sentence is terminated by semicolon. how can i select the complete sentense where my cursor is currently pointing.
0
Comment
Question by:krs_rama
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 2

Expert Comment

by:corvanderlinden
ID: 7061449
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

Const EM_LINEFROMCHAR = &HC9

'Determine the current line in a multiline TextBox control
Function GetTextBoxCurrentLine(TB As TextBox) As Long
   GetTextBoxCurrentLine = SendMessage(TB.hWnd, EM_LINEFROMCHAR, -1, ByVal 0&) + 1
End Function
0
 
LVL 39

Expert Comment

by:appari
ID: 7061528
try this
private sub SelectLine()
Dim i As Long
Dim j As Long
Dim k As Long

k = RichTextBox1.SelStart

If k = Len(Trim(RichTextBox1.Text)) Then Exit Sub
While j <= k
    i = j
    j = InStr(j + 1, RichTextBox1.Text, ";")
Wend
RichTextBox1.SelStart = i
RichTextBox1.SelLength = j - (i + 1)
end sub
0
 
LVL 39

Accepted Solution

by:
appari earned 150 total points
ID: 7061531
make sure to set hideselection property of richtextbox to false
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 43

Expert Comment

by:TimCottee
ID: 7061699
Or another method

Private Sub Command1_Click()
    Label1.Caption = GetSentence(RichTextBox1.Text, RichTextBox1.SelStart)
End Sub

Private Function GetSentence(ByVal RTBText As String, ByVal Position As Long) As String
    On Error Resume Next
    Dim lngCurrent As Long
    Dim lngStart As Long
    Dim lngEnd As Long
    lngStart = InStrRev(RTBText, ";", Position)
    lngEnd = InStr(Position, RTBText, ";")
    GetSentence = Mid(RTBText, lngStart + 1, lngEnd - lngStart - 1)
End Function

0
 
LVL 101

Expert Comment

by:mlmcc
ID: 7061873
Listening
0
 

Author Comment

by:krs_rama
ID: 7094756
good and thanks for the same
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 14 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question