tags:

views:

36

answers:

2

I would be grateful with some help with reading a text file into a Richtext box. The code I have at present appends the first line of text as I want it but the rest of the lines of text do not alter. I need a loop to read to the end of file and display in Richtext box. the code i have at present is this:-

Dim FILE_NAME As String = "C:\Test.txt"
Dim sr As New System.IO.StreamReader(FILE_NAME)
RichTextBox1.Text = sr.ReadToEnd

Dim sb As New System.Text.StringBuilder(RichTextBox1.Text)
sb.Insert(5, " ")
sb.Insert(12, " ")
sb.Insert(18, " ")
sb.Insert(25, " ")
sb.Insert(29, " ")
sb.Insert(32, " ")
sb.Insert(37, " ")
sb.Insert(44, " ")
sb.Insert(45, " ")

RichTextBox2.Text = sb.ToString

sr.Close()
A: 

I think you just want RichTextBox1.LoadFile "C:/test.txt"

that should be a backslash in the file name but my keyboard doesn't have one on this pc

developer
A: 

The reason for the spaces is because each line of text that have the same length characters with spaces needs to be seperated to make it more readable.The original text looks like this:-

17915WHITE BLUE 001.900116A T123456111

72451BLACK ORANGE000.500208 B A123456123 'worst case

72455BLACK WHITE 002.703501 C123456124

Needs to look like below.

17915:WHITE BLUE :001.9:001:16:A :T:123456:111

72451:BLACK ORANGE:000.5:002:08: B :A:123456:123

72455:BLACK WHITE :002.7:035:01: :C:123456:124

I can produce the first line to a text file but i cannot reproduce the rest of the lines of text i think i need a loop to keep reading over the text file until the file is read.

Keith
Keith, please update your original question, and don't add an answer. This is not a discussion forum.
John Saunders