By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,958 Members | 1,156 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,958 IT Pros & Developers. It's quick & easy.

Detect Word Wrap character

P: n/a
I have a VB app that has a richtextbox with the word wrap set to true. I need
to be able to output the text to a text file, but it just puts the text in
the file as one long line.

How do i replace word wrap (i.e. soft returns) with carriage returns?
Nov 23 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
"Jonathan Smith" <Jo***********@discussions.microsoft.com> schrieb:
I have a VB app that has a richtextbox with the word wrap set to true. I
need
to be able to output the text to a text file, but it just puts the text in
the file as one long line.

How do i replace word wrap (i.e. soft returns) with carriage returns?


A VB6 sample for the textbox control can be found here:

<URL:http://www.activevb.de/tipps/vb6tipps/tipp0098.html>

I assume that this technique can be applied to the richtextbox control too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #2

P: n/a
Unfortunately i do not know any german, so i am not exactly sure what that
code is.

At a very simple level, i need to know what Chr() value the wordwrap
character is (e.g. in the same way that carriage return is Chr(13) )

"Herfried K. Wagner [MVP]" wrote:
"Jonathan Smith" <Jo***********@discussions.microsoft.com> schrieb:
I have a VB app that has a richtextbox with the word wrap set to true. I
need
to be able to output the text to a text file, but it just puts the text in
the file as one long line.

How do i replace word wrap (i.e. soft returns) with carriage returns?


A VB6 sample for the textbox control can be found here:

<URL:http://www.activevb.de/tipps/vb6tipps/tipp0098.html>

I assume that this technique can be applied to the richtextbox control too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #3

P: n/a
Jonathan,

I don't know any Madarin, however if that page was written in Madarin, than
at least I would understand the code.

In German is written that any responsibility of the use of the code is at
the user himself for the rest.

Than there is this.
' Steuerelement: Listen-Steuerelement "List1"
Control Listbox is List1

' Steuerelement: Schaltfläche "Command1"
Control button is Command1

' Steuerelement: Textfeld "Text1"

Control textbox is text1

' Steuerelement: Beschriftungsfeld "Label1"
Control label is Label1.

In my opinion would any developper be able to understand this

In the code is not one word German.

Just my thought,

Cor
Nov 23 '05 #4

P: n/a
Having looked at the link again again, i can honestly say that it does not
address my problem at all.

I need to be able to replace wordwrap control chars with carriage returns.

"Cor Ligthert [MVP]" wrote:
Jonathan,

I don't know any Madarin, however if that page was written in Madarin, than
at least I would understand the code.

In German is written that any responsibility of the use of the code is at
the user himself for the rest.

Than there is this.
' Steuerelement: Listen-Steuerelement "List1"
Control Listbox is List1

' Steuerelement: Schaltfläche "Command1"
Control button is Command1

' Steuerelement: Textfeld "Text1"

Control textbox is text1

' Steuerelement: Beschriftungsfeld "Label1"
Control label is Label1.

In my opinion would any developper be able to understand this

In the code is not one word German.

Just my thought,

Cor

Nov 23 '05 #5

P: n/a
Hi,

Take a richtextboxes lines property.

http://msdn.microsoft.com/library/de...linestopic.asp

Ken
-----------------
"Jonathan Smith" <Jo***********@discussions.microsoft.com> wrote in message
news:46**********************************@microsof t.com...
I have a VB app that has a richtextbox with the word wrap set to true. I
need
to be able to output the text to a text file, but it just puts the text in
the file as one long line.

How do i replace word wrap (i.e. soft returns) with carriage returns?

Nov 23 '05 #6

P: n/a
Addendum:

The code below (quick and dirty) works pretty well here:

\\\
Private Overloads Declare Auto Function SendMessage Lib "user32" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As String _
) As Int32

Private Overloads Declare Auto Function SendMessage Lib "user32" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32 _
) As Int32

Private Const EM_GETLINE As Int32 = &HC4
Private Const EM_GETLINECOUNT As Int32 = &HBA
Private Const MAX_CHAR_PER_LINE As Int32 = &H100
Private Const EM_LINELENGTH As Int32 = &HC1
Private Const EM_LINEINDEX As Int32 = &HBB

Private Function GetLine( _
ByVal Text As TextBoxBase, _
ByVal Line As Integer _
) As String
Dim dwLineStart As Int32 = _
SendMessage(Text.Handle, EM_LINEINDEX, Line, 0)
Dim dwLineLen As Integer = _
SendMessage(Text.Handle, EM_LINELENGTH, dwLineStart, 0)
Dim Buff As String = _
Chr(dwLineLen And &HFF) & _
Chr(dwLineLen / &H100) & _
Space(dwLineLen)
Dim dwLen As Int32 = _
SendMessage(Text.Handle, EM_GETLINE, Line, Buff)
GetLine = Strings.Left(Buff, dwLen)
End Function

Private Sub Button2_Click( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles Button2.Click
Dim Max As Int32
Max = _
SendMessage( _
Me.RichTextBox1.Handle, EM_GETLINECOUNT, 0, 0 _
) - 1
Me.ListBox1.Items.Clear()
For i As Integer = 0 To Max
Me.ListBox1.Items.Add(GetLine(Me.RichTextBox1, i))
Next i
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 23 '05 #7

P: n/a
"Ken Tucker [MVP]" <vb***@bellsouth.net> schrieb:
Take a richtextboxes lines property.


The 'Lines' property will ony return the lines separated by new line
character sequences.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #8

P: n/a
Although that code copies the text, it does not maintain any formatting, like
red text, bold text etc..

"Herfried K. Wagner [MVP]" wrote:
Addendum:

The code below (quick and dirty) works pretty well here:

\\\
Private Overloads Declare Auto Function SendMessage Lib "user32" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As String _
) As Int32

Private Overloads Declare Auto Function SendMessage Lib "user32" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32 _
) As Int32

Private Const EM_GETLINE As Int32 = &HC4
Private Const EM_GETLINECOUNT As Int32 = &HBA
Private Const MAX_CHAR_PER_LINE As Int32 = &H100
Private Const EM_LINELENGTH As Int32 = &HC1
Private Const EM_LINEINDEX As Int32 = &HBB

Private Function GetLine( _
ByVal Text As TextBoxBase, _
ByVal Line As Integer _
) As String
Dim dwLineStart As Int32 = _
SendMessage(Text.Handle, EM_LINEINDEX, Line, 0)
Dim dwLineLen As Integer = _
SendMessage(Text.Handle, EM_LINELENGTH, dwLineStart, 0)
Dim Buff As String = _
Chr(dwLineLen And &HFF) & _
Chr(dwLineLen / &H100) & _
Space(dwLineLen)
Dim dwLen As Int32 = _
SendMessage(Text.Handle, EM_GETLINE, Line, Buff)
GetLine = Strings.Left(Buff, dwLen)
End Function

Private Sub Button2_Click( _
ByVal sender As Object, _
ByVal e As EventArgs _
) Handles Button2.Click
Dim Max As Int32
Max = _
SendMessage( _
Me.RichTextBox1.Handle, EM_GETLINECOUNT, 0, 0 _
) - 1
Me.ListBox1.Items.Clear()
For i As Integer = 0 To Max
Me.ListBox1.Items.Add(GetLine(Me.RichTextBox1, i))
Next i
End Sub
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #9

P: n/a
If i use the EM_GETLINES call, how do i copy the richtext formatting aswell???
Nov 23 '05 #10

P: n/a
"Jonathan Smith" <Jo***********@discussions.microsoft.com> schrieb:
Although that code copies the text, it does not maintain any formatting,
like
red text, bold text etc..


That's true. I feel sorry, but I currently do not know a way to preserve
the formatting.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.