Solved

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

Posted on 2002-06-07
6
272 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
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

776 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