unable to change text in richtextbox


C

Co

Hi All.

I read text from a word file into a richttextbox in a form.
Because it's not always done correct I change some things. Remove some
strange
characters and give some additional extra returns.

When I click the forms Save button I want the text to be copied to a
string.
But it doesn't copy my changes because the original text before
editing will be copied:

Private Sub frmSamenvatting_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
RichTextBox1.Text = ""
'we can only read from doc files
If Path.GetExtension(iD) = ".doc" Then
Call readdoc(iD)
End If
End Sub

Sub readdoc(ByVal sPathName As String)

Dim fs As FileStream = File.OpenRead(sPathName)
'declaring a FileStream to open the file named file.doc with
access mode of reading
Dim d As New StreamReader(fs)

'creating a new StreamReader and passing the filestream object
fs as argument
d.BaseStream.Seek(0, SeekOrigin.Begin)
'Seek method is used to move the cursor to different positions
in a file, in this code, to
'the beginning
While d.Peek() > -1
'peek method of StreamReader object tells how much more
data is left in the file
Me.RichTextBox1.Text &= d.ReadLine()
End While
d.Close()

End Sub

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click
sSVatting = Me.RichTextBox1.Text
Me.Close()
End Sub

Regards
Marco
The Netherlands
 
Ad

Advertisements

J

James Hahn

You haven't indicated what sSVatting is or how or where it is declared, so I
replaced your last function with:

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click
Dim sSVatting As String
sSVatting = Me.RichTextBox1.Text
RichTextBox2.Text = sSVatting
End Sub

and it worked just as I would expect - the edited text was copied into the
second text box.

How are you examining the result of the edits?
 
J

James Hahn

You haven't indicated what sSVatting is or how or where it is declared, so I
replaced your last function with:

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click
Dim sSVatting As String
sSVatting = Me.RichTextBox1.Text
RichTextBox2.Text = sSVatting
End Sub

and it worked just as I would expect - the edited text was copied into the
second text box.

How are you examining the result of the edits?
 
C

Co

You haven't indicated what sSVatting is or how or where it is declared, so I
replaced your last function with:

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click
Dim sSVatting As String
sSVatting = Me.RichTextBox1.Text
RichTextBox2.Text = sSVatting
End Sub

and it worked just as I would expect - the edited text was copied into the
second text box.

How are you examining the result of the edits?















- Tekst uit oorspronkelijk bericht weergeven -

James,

sSvatting is declared Public as a string.
The content gets copied to a memo field in a ms access database.
From there it is displayed again with the other fields of the record
on a form.
The memofield is displayed in a Richtextbox.

HTH

Marco
 
C

Co

You haven't indicated what sSVatting is or how or where it is declared, so I
replaced your last function with:

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click
Dim sSVatting As String
sSVatting = Me.RichTextBox1.Text
RichTextBox2.Text = sSVatting
End Sub

and it worked just as I would expect - the edited text was copied into the
second text box.

How are you examining the result of the edits?















- Tekst uit oorspronkelijk bericht weergeven -

James,

sSvatting is declared Public as a string.
The content gets copied to a memo field in a ms access database.
From there it is displayed again with the other fields of the record
on a form.
The memofield is displayed in a Richtextbox.

HTH

Marco
 
J

James Hahn

In that case I would guess that storing it as a memofield is re-creating the
problem (such as extra strange characters) that you originally needed to
edit in that field. You will need to examine the text at every stage of its
processing to identify exactly where it is getting corrupted, as my testing
indicates it is not happening as a result of storing the rich text box text
in a string variable.

You haven't indicated what sSVatting is or how or where it is declared, so
I
replaced your last function with:

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click
Dim sSVatting As String
sSVatting = Me.RichTextBox1.Text
RichTextBox2.Text = sSVatting
End Sub

and it worked just as I would expect - the edited text was copied into the
second text box.

How are you examining the result of the edits?















- Tekst uit oorspronkelijk bericht weergeven -

James,

sSvatting is declared Public as a string.
The content gets copied to a memo field in a ms access database.
From there it is displayed again with the other fields of the record
on a form.
The memofield is displayed in a Richtextbox.

HTH

Marco
 
Ad

Advertisements

J

James Hahn

In that case I would guess that storing it as a memofield is re-creating the
problem (such as extra strange characters) that you originally needed to
edit in that field. You will need to examine the text at every stage of its
processing to identify exactly where it is getting corrupted, as my testing
indicates it is not happening as a result of storing the rich text box text
in a string variable.

You haven't indicated what sSVatting is or how or where it is declared, so
I
replaced your last function with:

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click
Dim sSVatting As String
sSVatting = Me.RichTextBox1.Text
RichTextBox2.Text = sSVatting
End Sub

and it worked just as I would expect - the edited text was copied into the
second text box.

How are you examining the result of the edits?















- Tekst uit oorspronkelijk bericht weergeven -

James,

sSvatting is declared Public as a string.
The content gets copied to a memo field in a ms access database.
From there it is displayed again with the other fields of the record
on a form.
The memofield is displayed in a Richtextbox.

HTH

Marco
 
J

James Hahn

In that case I would guess that storing it as a memofield is re-creating the
problem (such as extra strange characters) that you originally needed to
edit in that field. You will need to examine the text at every stage of its
processing to identify exactly where it is getting corrupted, as my testing
indicates it is not happening as a result of storing the rich text box text
in a string variable.

You haven't indicated what sSVatting is or how or where it is declared, so
I
replaced your last function with:

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click
Dim sSVatting As String
sSVatting = Me.RichTextBox1.Text
RichTextBox2.Text = sSVatting
End Sub

and it worked just as I would expect - the edited text was copied into the
second text box.

How are you examining the result of the edits?















- Tekst uit oorspronkelijk bericht weergeven -

James,

sSvatting is declared Public as a string.
The content gets copied to a memo field in a ms access database.
From there it is displayed again with the other fields of the record
on a form.
The memofield is displayed in a Richtextbox.

HTH

Marco
 
J

James Hahn

In that case I would guess that storing it as a memofield is re-creating the
problem (such as extra strange characters) that you originally needed to
edit in that field. You will need to examine the text at every stage of its
processing to identify exactly where it is getting corrupted, as my testing
indicates it is not happening as a result of storing the rich text box text
in a string variable.

You haven't indicated what sSVatting is or how or where it is declared, so
I
replaced your last function with:

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnSave.Click
Dim sSVatting As String
sSVatting = Me.RichTextBox1.Text
RichTextBox2.Text = sSVatting
End Sub

and it worked just as I would expect - the edited text was copied into the
second text box.

How are you examining the result of the edits?















- Tekst uit oorspronkelijk bericht weergeven -

James,

sSvatting is declared Public as a string.
The content gets copied to a memo field in a ms access database.
From there it is displayed again with the other fields of the record
on a form.
The memofield is displayed in a Richtextbox.

HTH

Marco
 
R

Roomy R. Shroff

Hi,

Instead of using Me.RichTextBox1.Text for RichTextBoxes use
Me.RichTextBox1.Rtf - both strings.
Then do not change the string while saving or while loading the RichTextBox.

The strange characters are part of the RTF, keep them.
 
R

Roomy R. Shroff

Hi,

Instead of using Me.RichTextBox1.Text for RichTextBoxes use
Me.RichTextBox1.Rtf - both strings.
Then do not change the string while saving or while loading the RichTextBox.

The strange characters are part of the RTF, keep them.
 
Ad

Advertisements

C

Co

Hi,

Instead of using Me.RichTextBox1.Text for RichTextBoxes use
Me.RichTextBox1.Rtf - both strings.
Then do not change the string while saving or while loading the RichTextBox.

The strange characters are part of the RTF, keep them.

Roomy,

If you follow your lead then nothing appears in my rtf box.
When I open the record I see only this in the rtf box:

{\rtf1\ansi\ansicpg1252\deff0\deflang1043{\fonttbl{\f0\fnil\fcharset0
Microsoft Sans Serif;}}
\viewkind4\uc1\pard\f0\fs17\par
}

The code that reads the document:

Sub readdoc(ByVal sPathName As String)

Dim fs As FileStream = File.OpenRead(sPathName)
'declaring a FileStream to open the file named file.doc with
access mode of reading
Dim d As New StreamReader(fs)

'creating a new StreamReader and passing the filestream object
fs as argument
d.BaseStream.Seek(0, SeekOrigin.Begin)
'Seek method is used to move the cursor to different positions
in a file, in this code, to
'the beginning
While d.Peek() > -1
'peek method of StreamReader object tells how much more
data is left in the file
Me.RichTextBox1.Rtf &= d.ReadLine()
End While
d.Close()

End Sub

Marco
 
Ad

Advertisements

C

Co

Hi,

Instead of using Me.RichTextBox1.Text for RichTextBoxes use
Me.RichTextBox1.Rtf - both strings.
Then do not change the string while saving or while loading the RichTextBox.

The strange characters are part of the RTF, keep them.

Roomy,

If you follow your lead then nothing appears in my rtf box.
When I open the record I see only this in the rtf box:

{\rtf1\ansi\ansicpg1252\deff0\deflang1043{\fonttbl{\f0\fnil\fcharset0
Microsoft Sans Serif;}}
\viewkind4\uc1\pard\f0\fs17\par
}

The code that reads the document:

Sub readdoc(ByVal sPathName As String)

Dim fs As FileStream = File.OpenRead(sPathName)
'declaring a FileStream to open the file named file.doc with
access mode of reading
Dim d As New StreamReader(fs)

'creating a new StreamReader and passing the filestream object
fs as argument
d.BaseStream.Seek(0, SeekOrigin.Begin)
'Seek method is used to move the cursor to different positions
in a file, in this code, to
'the beginning
While d.Peek() > -1
'peek method of StreamReader object tells how much more
data is left in the file
Me.RichTextBox1.Rtf &= d.ReadLine()
End While
d.Close()

End Sub

Marco
 

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

Top