Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Richtextpox adding newline HOW CAN IT BE STOPPED?

Status
Not open for further replies.

three57m

Programmer
Jun 13, 2006
202
US
OK Instead of going into great detail explaining the problem I set up a quick easy example so others can test.
Just follow the commented test instructions. Any help would be greatly appreciated [yinyang]

Code:
'TO TEST

'Add 2 Richtextboxes 'SET SCROLL BARS TO BOTH FOR YOUR CONVENIENCE
'Add 2 Command Buttons
'Add 2 Labels
'Paste Code

'GOTO the website> [URL unfurl="true"]http://www.gamefaqs.com/ps2/914828-metal-gear-solid-3-snake-eater/faqs/35928[/URL]
'Right click and select "All Text"
'paste text into >>RichTextbox1<<

'Click the Command1 button

'you will see that the length of richtextbox1
'is different from richtextbox2 , the richtext boxes are for some reason adding \par

'By clicking command2 and repeating you will see a continued addition in the length


Private Sub Command1_Click()
    RichTextBox2.TextRTF = RichTextBox1.TextRTF
    Label1.Caption = "RichText#1 Length = " & Len(RichTextBox1.Text)
    Label2.Caption = "RichText#2 Length = " & Len(RichTextBox2.Text)
End Sub

Private Sub Command2_Click()
    RichTextBox1.TextRTF = RichTextBox2.TextRTF
    Label1.Caption = "RichText#1 Length = " & Len(RichTextBox1.Text)
    Label2.Caption = "RichText#2 Length = " & Len(RichTextBox2.Text)
End Sub

Private Sub Form_Load()
    'Set up form and control positions for testing ease
    Me.Width = 15360
    Me.Height = 8295
    
    RichTextBox1.AutoVerbMenu = True
   
    RichTextBox1.Height = 5000
    RichTextBox1.Width = 6735
    RichTextBox1.Top = 120
    RichTextBox1.Left = 120
    
    
    RichTextBox2.Height = 5000
    RichTextBox2.Width = 6735
    RichTextBox2.Top = 120
    RichTextBox2.Left = 8280
    
    Command1.Caption = ">"
    Command1.Top = 120
    Command1.Left = 6960
    
    Command2.Caption = "<"
    Command2.Top = 4560
    Command2.Left = 6960
    
    Label1.Caption = ""
    Label1.Top = 5160
    Label1.Left = 3000
    
    Label2.Caption = ""
    Label2.Top = 5160
    Label2.Left = 11100
End Sub
 
I've tried your example and I've tried things to prevent this happening but I can't make it work as you would expect it to. However it does seem to be something to do with the source you're copying. If for example you right-click and select all on this page and paste it in, the character counts are the same.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Please be aware that the Richtextbox's ability to convert from HTML (your source) to RTF is not particularly good, and can sometime introduce artifacts into the internal representation of the text - which is what seems to be the case here ...

In your case, the troublesome character is located at position 98830

and the following fixes the problem in this particular case if used immediately after pasting in the text:

RichTextBox1.SelStart = 98830
RichTextBox1.SelLength = 1
RichTextBox1.SelText = ""

However, it is not a generic fix, nor am I aware of a methof of determining ahead of time where such an error may occur.
 
It appears I will need to develop a work around for this problem. Thank you both for the responses.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top