krs_rama
asked on
How to select a sentence from a rich text box control ?
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.
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
private sub SelectLine()
Dim i As Long
Dim j As Long
Dim k As Long
k = RichTextBox1.SelStart
If k = Len(Trim(RichTextBox1.Text
While j <= k
i = j
j = InStr(j + 1, RichTextBox1.Text, ";")
Wend
RichTextBox1.SelStart = i
RichTextBox1.SelLength = j - (i + 1)
end sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Or another method
Private Sub Command1_Click()
Label1.Caption = GetSentence(RichTextBox1.T ext, 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
Private Sub Command1_Click()
Label1.Caption = GetSentence(RichTextBox1.T
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
Listening
ASKER
good and thanks for the same
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