Detect Word Wrap character

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
Jonathan Smith said:
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.
 
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) )
 
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
 
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.
 
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
///
 
Ken Tucker said:
Take a richtextboxes lines property.

The 'Lines' property will ony return the lines separated by new line
character sequences.
 
Although that code copies the text, it does not maintain any formatting, like
red text, bold text etc..
 
Jonathan Smith said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top