Solved

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

Posted on 2002-06-07
6
274 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 50 total points
ID: 7061531
make sure to set hideselection property of richtextbox to false
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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 100

Expert Comment

by:mlmcc
ID: 7061873
Listening
0
 

Author Comment

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

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

739 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