0

Hi guys,

I am trying to create an windows application.
What I need to do at this stage is I am trying to read a tab delimited file and the that same tab delimited file to go to another text file on my C drive.
I have written some code and managed to read the file ok as well as write it to the new file.
However I don`t seem to get around the formating in the new file.
Meaning I get so far all te original file as single string in the new file.
What I need is to get the new file so that every record is 800 characters in lenght(including tab delimiters in that number)so that I can have same number of rows as in the original file.
I will have to later perform some conditional split on certain criteria that`s why it`s important that I get the file in the right format as a start.
Here is my code so far :

Private Sub Read_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Click
        Dim fs As New FileStream("C:\Test\OMLifeTestFile.txt", FileMode.Open, FileAccess.Read)


        RichTextBox1.Text = ""
        Dim d As New StreamReader(fs)

        d.BaseStream.Seek(0, SeekOrigin.Begin)
        
        While d.Peek() > -1

            RichTextBox1.Text &= d.ReadLine()

        End While
        d.Close()

    End Sub
 Private Sub write_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Click
        Dim fs As New FileStream("C:\Test\Test1.txt", FileMode.Open, FileAccess.Write)

        Dim s As New StreamWriter(fs)

        s.WriteLine(RichTextBox1.Text.ToString())


        s.Close()

    End Sub

I also tried using the following for the read and write parts and managed the first row displayed ok on the new file , but only the first row :(

Private Sub Read_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Click
        Dim fs As New FileStream("C:\Test\OMLifeTestFile.txt", FileMode.Open, FileAccess.Read)


        RichTextBox1.Text = ""
        Dim d As New StreamReader(fs)
        d.BaseStream.Seek(0, SeekOrigin.Begin)

        While d.Peek() > -1
            Dim s As String = d.ReadLine()

            If s.Length > 800 Then

                s = s.Remove(800) & Environment.NewLine
            End If

            RichTextBox1.Text &= s
        End While
        d.Close()

    End Sub

Private Sub write_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Click
        Dim fs As New FileStream("C:\Test\Test1.txt", FileMode.Open, FileAccess.Write)

        Dim s As New StreamWriter(fs)

        s.WriteLine(RichTextBox1.Text.Remove(800) & Environment.NewLine)



        s.Close()

    End Sub

Now I am continuing to work on that but if someone can help would be greatly appreciated.
Thank you

1
Contributor
1
Reply
3
Views
8 Years
Discussion Span
Last Post by mem81
0

Hey guys fixed it. Here is the code:

Private Sub Read_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Click
        Dim fs As New FileStream("C:\Test\File.txt", FileMode.Open, FileAccess.Read)


        RichTextBox1.Text = ""
        Dim d As New StreamReader(fs)
        d.BaseStream.Seek(0, SeekOrigin.Begin)

        While d.Peek() > -1
            Dim s As  String = d.ReadLine()

            If s.Length > 800 Then

                s = s.Remove(800)
            End If

            RichTextBox1.Text &= s & Environment.NewLine
        End While
        d.Close()
        Dim fs1 As New FileStream("C:\Test\a.txt", FileMode.Create, FileAccess.Write)
        Dim ss As New StreamWriter(fs1)
        ss.WriteLine(RichTextBox1.Text)
        ss.Close()



    End Sub

:)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.