Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do I prevent Growing Line Spacing in RichTextBox Control

Posted on 2008-11-12
7
Medium Priority
?
965 Views
Last Modified: 2013-12-20
I have two RichTextbox controls on a MS-Access form.When I moved data from one control to another, extra \par markers are inserted.  This action is not consistent among several machines, even when the versions of RichTx32.ock, Riched20.dll and Riched32.dll are in the same versions.
Specifically, in this simple statemnt is where the trouble occurs:
Public Sub SetBody(TextRTF As String, ImageString As String)
       
    R.TextRTF = TextRTF                                    '(RP) set the RTF..

TextRtf a string with the following contents

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}{\f1\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue255;}
{\*\generator Riched20 5.50.99.2050;}\viewkind4\uc1\pard\qc\cf1\f0\fs48\lang1033 VIP Medicine, LLC
\par
\par
\par
\par \fs24 12755 58th Street Mayer, MN 55360 800-652-3739\cf0\f1\fs17
\par
\par
\par
\par \pard
\par
\par
\par
\par
\par Yours Truly,entMD]
\par
\par
\par
\par }

Notice that there are \par tokens between the first two printable lines.  The target control, R is a Richtx32.ocx ActiveX control.  Upon execution of this single statement, the contents of R.TextRTF are now 5 \par tokens between the first two printable lines.  In addition, another extra \par token has been added at the end.

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}{\f1\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue255;}
{\*\generator Riched20 5.50.99.2050;}\viewkind4\uc1\pard\qc\cf1\f0\fs48\lang1033 VIP Medicine, LLC
\par
\par
\par
\par
\par \fs24 12755 58th Street Mayer, MN 55360 800-652-3739\cf0\f1\fs17
\par
\par
\par
\par
\par \pard
\par
\par
\par
\par
\par Yours Truly,entMD]
\par
\par
\par
\par
\par }

What is going on here and how can I prevent it.  Note also that upon research, the data streams are slightly different on the working machines, but only in the \Generator token.  On a machine where extra tokens are bein inserted, it is:

{\*\generator Riched20 5.50.99.2050;}

On a machine where there are no extra tokens being inserted, it is:

{\*\generator Riched20 5.50.30.2002;}\

If this is a version-related problem, how do I version level.  I have tried changing versions of Richtx32.ocx, Riched20.dll and riched32.dll, all to no avail.  The problem occurrs on Vista, Win/Xp and Win2k machines.  ON onther machine with the same OS, it does not occur.

one other thing I noticed that might be helpful.  In environments where the extra token is inserted, a CRLF(Asc(13) & Asc(10) moved into the text component results in two \par tokens being generated in the rtf.  In the non-failing environments, that sequence result in only 1 \par being generate.

0
Comment
Question by:RickHolt
  • 3
  • 2
  • 2
7 Comments
 
LVL 7

Expert Comment

by:rheitzman
ID: 22945652
RichTextBoxes as a constant hassle when used with Access. If you can avoid them I'd suggest you do.

One trick to make things easier is to create an object that will work with the VBE Intellisense:

    Dim rtb As RichTextBox
    Set rtb = Me.R

Doing this will expose some to the hidden methods and properties of the control and make you life easier.

For example you can extract the text only (with line ends) from a Rich box:

   sText = rtb.Text

You can then assign the sText to another RichTextBox. You will loose formating of fonts but the text and line ends survives.

Sloshing the RTF between boxes using an external file sometimes works.

Don't expect RichTextBoxes to work on a Tab control. If you have to do that bind the control at the last moment (when the tab is made active.)

Expect weird problems.... Like a while back an automatic update changed something about the way line ends were encoded into RTF....

Hopefully there is something in the post that helps....


0
 
LVL 7

Expert Comment

by:rheitzman
ID: 22945680
You might try stripping out an CrLf pairs that may be in the RTF string

R.TextRTF = Replace(TextRTF, vbCrLf)

You might need to filter for just a single vbCr or vbLf.
0
 

Author Comment

by:RickHolt
ID: 22945871
Unfortunately, the application would need to be rewritten to remove reliance on rich Text box controls.  I will try the method you mention just in case it exposes some kind of method or parameter that I have not seen in my extensive web searches and will respond if I find anything fruitful.
0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
LVL 22

Expert Comment

by:danaseaman
ID: 22945977
This is what I use for API created RichEdit to prevent extra vbCrLF(/par).
Please try this an let me know if it fixes the issue.

Private Const WM_USER = &H400
Private Const EM_SETEDITSTYLE = WM_USER + 204
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
 
SendMessage RichTextBox1.hWnd, EM_SETEDITSTYLE, 1&, 1&

Open in new window

0
 
LVL 22

Expert Comment

by:danaseaman
ID: 22946339
Update

Private Const WM_USER = &H400
Private Const EM_SETEDITSTYLE = WM_USER + 204
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
 
SendMessageLong RichTextBox1.hWnd, EM_SETEDITSTYLE, 1&, 1&

Open in new window

0
 

Author Comment

by:RickHolt
ID: 22969791
I tried to take this advice, but it did not seem to operate without the flaws cited.  That
is, the SendMessage appears to have no effect.  Below is the code sequence and the result.  
Keep in mind that R and R2 are RichTextBox ActiveX controls on an MS-Access form called
Correspondence_Editor.

First, the setup for the SendMessage API Call.  This is in the Declarations section of the form.

Private Const WM_USER = &H400
Private Const EM_SETEDITSTYLE = WM_USER + 204
Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long


I am executing the exact same codein the Correspondence_editor form shown in the initial report with the exeception of the SendMessageLong, so we have the following:

    SendMessageLong Me!R.hWnd, EM_SETEDITSTYLE, 1&, 1&
    R.TextRTF = TextRTF                                    '(RP) set the RTF..

Before the executionof the SendMessage, the contents of TextRtf are as follows:

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}{\f1\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue255;}
{\*\generator Riched20 5.50.99.2050;}\viewkind4\uc1\pard\qc\cf1\f0\fs48\lang1033 VIP Medicine, LLC
\par
\par
\par
\par
\par \fs24 12755 58th Street Mayer, MN 55360 800-652-3739\cf0\f1\fs17
\par
\par
\par
\par \pard
\par
\par
\par
\par
\par
\par
\par
\par }

The return code of the SendMessageLong is 0

After execution of the R.TextRTF = TextRTF, the contents of R.TextRTF is:

{\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}{\f1\fnil\fcharset0 MS Sans Serif;}}
{\colortbl ;\red0\green0\blue255;}
{\*\generator Riched20 5.50.99.2050;}\viewkind4\uc1\pard\qc\cf1\f0\fs48\lang1033 VIP Medicine, LLC
\par
\par
\par
\par
\par
\par \fs24 12755 58th Street Mayer, MN 55360 800-652-3739\cf0\f1\fs17
\par
\par
\par
\par
\par \pard
\par
\par
\par
\par
\par
\par
\par
\par
\par }

Despite the SendMessage, The same additional \par was added after the first text line, after the second text line and after the \pard.  Therefore, I conclude that the suggested solution does not work.  Perhaps I missed something?
[btw, I tried to respond individually to suggested soultions, but clicking onthe No box is causing Errors on the we page.]
0
 

Accepted Solution

by:
RickHolt earned 0 total points
ID: 22995545
Upon further experimentation, this seems to be due to flaws in the Richtx32.ocx itself.  I have used instead a third party replacement control, Chado SpellEditor control, that does exhibit the problem noted in this problem description.  Though there are probably others, this one uses all the same property, method and object names as the Richtx32.ocx does and seems to behave the sam in all windows environmets.
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Windows Explorer let you handle zip folders nearly as any other folder: Copy, move, change, and delete, etc. In VBA you can also handle normal files and folders, but zip folders takes a little more - and that you'll find here.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question