Solved

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

Posted on 2002-06-07
6
270 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
6 Comments
 
LVL 2

Expert Comment

by:corvanderlinden
Comment Utility
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
Comment Utility
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
Comment Utility
make sure to set hideselection property of richtextbox to false
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 43

Expert Comment

by:TimCottee
Comment Utility
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
Comment Utility
Listening
0
 

Author Comment

by:krs_rama
Comment Utility
good and thanks for the same
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
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…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now