Losing chr(13) when copy string to Rich Text Box
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: Losing chr(13) when copy string to Rich Text Box

  1. #1
    Join Date
    Aug 2010
    Posts
    41

    Losing chr(13) when copy string to Rich Text Box

    I have had some strange behaviour in a program I am moving from VB6 to vb.net and finally discovered that I am losing a character when I do the following:

    Code:
    Private Sub Form1_Load( ByVal sender As System.Object,  ByVal e As System.EventArgs) Handles MyBase.Load
    
      Dim intChr10  As Integer 
      Dim intChr13  As Integer 
      Dim intLength As Integer 
      Dim strM      As String 
    
      strM =        "Line 1" & vbCrLf 
      strM = strM & "Line 2" & vbCrLf 
      strM = strM & "Line 3" & vbCrLf 
      strM = strM & "Line 4" & vbCrLf 
    
      intChr10 = CountCharacter(strM, Chr(10))  ' = 4
      intChr13 = CountCharacter(strM, Chr(13))  ' = 4
      intLength = Len(strM)                     ' = 32
    
      RichTextBox1.Text = strM
      intLength = Len(RichTextBox1.Text)         ' = 28
    
      intChr10 = CountCharacter(CStr(RichTextBox1.Text), Chr(10))  ' = 4
      intChr13 = CountCharacter(CStr(RichTextBox1.Text), Chr(13))  ' = 0
    
    End Sub
    
    Private Function CountCharacter(strSample As String, ch As Char) As Integer
      Dim cnt As Integer = 0
    
      For Each c As Char In strSample
        If c = ch Then cnt += 1
      Next
    
      Return cnt
    End Function
    Specifically, copying the string to the RTB seems to change vbCrLf into vbLf ie it seems to lose Chr(13). Anybody understand this?

    Many thanks ...
    Last edited by wavering; July 12th, 2014 at 07:28 AM.
    MOPEKS - a freeware program that generates programs that use each other to solve problems

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center