July 12th, 2014, 07:20 AM
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:
Specifically, copying the string to the RTB seems to change vbCrLf into vbLf ie it seems to lose Chr(13). Anybody understand this?
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
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
Many thanks ...
Last edited by wavering; July 12th, 2014 at 07:28 AM.
- a freeware program that generates programs that use each other to solve problems. Is this the correct route to a genuinely intelligent machine?
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.