473,326 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Retrieving each line from a RichTextBox...

....without resorting to SendMessage. Imagine, for example,
I have a small RTB whose text has wrapped as follows:

"This is a small test to see if I can get"
"both of these lines".

GetLineFromCharIndex(RTB.TextLength) returns 1, telling me
there are two lines in there. Using the Lines property to
retrieve them will fail, however. As the line has
soft-wrapped (i.e. the user has not hit Enter after "get"),
it returns "This is a small test to see if I can get both of
these lines".

In VB6, SendMessage would come to the rescue here. Is there
a managed way of achieving the same thing?
Nov 21 '05 #1
2 1557
Not sure if this helps, but........

I used this in VBA, it might come in handy. It does exactly what you want.
You would just need to translate it. (sorry!)

Function GetLines() As Variant
Dim lLines As Long
With MyForm.RichText1
.SetFocus
lLines = .LineCount
End With

ReDim arrTmp(lLines) As String
For X = 1 To lLines
'Set and select linenumber
SetLine X
'pick up text in line
arrTmp(X) = n
Next
'return values to function
GetLines = arrTmp
Erase arrTmp

End Function

Sub SetLine(ByVal LineNumber As Integer)
On Error Resume Next
'set linenumber
MyForm.RichText1.CurLine = LineNumber - 1
'make selection using sendkeys (argghh)
SendKeys "{HOME}", -1
SendKeys "+{END}", -1
If Err <> 0 Then Err.Clear
End Sub

--

Bob

--------------------------------------
I'll have a B please Bob.

"Mark Raishbrook" <ra********@mail.telepac.pt> wrote in message
news:41**********************@news.telepac.pt...
...without resorting to SendMessage. Imagine, for example,
I have a small RTB whose text has wrapped as follows:

"This is a small test to see if I can get"
"both of these lines".

GetLineFromCharIndex(RTB.TextLength) returns 1, telling me
there are two lines in there. Using the Lines property to
retrieve them will fail, however. As the line has
soft-wrapped (i.e. the user has not hit Enter after "get"),
it returns "This is a small test to see if I can get both of
these lines".

In VB6, SendMessage would come to the rescue here. Is there
a managed way of achieving the same thing?

Nov 21 '05 #2
Thanks for that, Bob. I'd rather not use SendKeys, but if
all else fails I'll give it a go.

"Bob Hollness" <bo*@blockbuster.com> wrote in message
news:ev*************@TK2MSFTNGP15.phx.gbl...
Not sure if this helps, but........

I used this in VBA, it might come in handy. It does
exactly what you want. You would just need to translate
it. (sorry!)

Function GetLines() As Variant
Dim lLines As Long
With MyForm.RichText1
.SetFocus
lLines = .LineCount
End With

ReDim arrTmp(lLines) As String
For X = 1 To lLines
'Set and select linenumber
SetLine X
'pick up text in line
arrTmp(X) = n
Next
'return values to function
GetLines = arrTmp
Erase arrTmp

End Function

Sub SetLine(ByVal LineNumber As Integer)
On Error Resume Next
'set linenumber
MyForm.RichText1.CurLine = LineNumber - 1
'make selection using sendkeys (argghh)
SendKeys "{HOME}", -1
SendKeys "+{END}", -1
If Err <> 0 Then Err.Clear
End Sub

--

Bob

--------------------------------------
I'll have a B please Bob.

"Mark Raishbrook" <ra********@mail.telepac.pt> wrote in
message news:41**********************@news.telepac.pt...
...without resorting to SendMessage. Imagine, for
example,
I have a small RTB whose text has wrapped as follows:

"This is a small test to see if I can get"
"both of these lines".

GetLineFromCharIndex(RTB.TextLength) returns 1, telling
me
there are two lines in there. Using the Lines property to
retrieve them will fail, however. As the line has
soft-wrapped (i.e. the user has not hit Enter after
"get"),
it returns "This is a small test to see if I can get both
of
these lines".

In VB6, SendMessage would come to the rescue here. Is
there
a managed way of achieving the same thing?


Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Martin Dew | last post by:
I have a RichTextBox called rtbOutput. I am adding lines of text using the AppendText method. What I want to do is immediately after adding this line of text make sure that this line of text is...
6
by: Rachel Suddeth | last post by:
I have the index of a line in the Lines array of a RichTextBox. I would like to have it scroll so that line displays at the top. Is there no way to do this? The only way I can see to make it...
22
by: DraguVaso | last post by:
Hi, For my application I need the following behavior: When I press F4 the cursor has to move to the next line in my multiline textbox which begins with "0". Finding lines starting with 0 isn't...
4
by: M O J O | last post by:
Hi, I'm using a RichTextBox with WordWrap=True and MultiLine=False. When the text is to long, it fills more lines. How do I get the number of lines the text uses? Thanks!
2
by: Just Me | last post by:
I insert text in a RichTextBox ending each line with vbCrLf. I think when I search the RichTextBox text I do not find any CR's. In the Text property is the end of line char a LineFeed? Are...
0
by: John Smith | last post by:
I have text files and I get binary offsets of text portion of these files from VB6 program with RichTextBox. I use VB.Net 2003 and need to select and highlight the text between given offsets....
0
by: talon83 | last post by:
Ok, I am wondering how do I set the amount of characters per line that a richtextbox will have. I have a save dialog code and i want to set the characters to 64 characters then goto another line and...
4
by: Franky | last post by:
What I want to do is delete the last line in a RichTextBox. The RichTextBox has a ReadOnly property called lines that seems like it might help but I cant figure out how to use it. Well, the...
2
by: aemihal | last post by:
Hello, I have a RichTextBox that has a large number of lines, well in excess of the amount that can be seen without scrolling. Upon an event, such as clicking a button, I would like to move the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.