0

Hello,

Im newbie at VB and i need help solving my issue please

The code i used:

Dim SaveFile As New SaveFileDialog
            SaveFile.FileName = ""
            SaveFile.Filter = "Text Files (*.txt)|*.txt"
            SaveFile.Title = "Save"
            SaveFile.ShowDialog()
            Try
                Dim Write As New System.IO.StreamWriter(SaveFile.FileName)
                Write.Write(RichTextBox1.Text)
                Write.Close()
            Catch ex As Exception
            End Try

The problem is that when i save the text file

It be from

A
B
C
D
E
F

TO ONE LINE

ABCDEF

Hope someone could help me, thanks in advance

3
Contributors
17
Replies
20
Views
5 Years
Discussion Span
Last Post by sylvester3
0

I set up a test exactly as you specified and my text file contains

A
B
C
D
E
F

Can you possibly post a screenshot of your app running?

0

I usually use TextPad instead of Notepad and I have seen multiple lines display as one in notepad when the lines end with a line feed only rather than carriage return+line feed. TextPad doesn't have this problem. What happens if you list the contents of the file from the command line (using the TYPE command)?

0

looks like the issue from the richtextbox, i will give a try for textbox and then reply

0
'// TextBox.
        IO.File.WriteAllText("full.path of file here", TextBox1.Text)
        '// RichTextBox.
        RichTextBox1.SaveFile("full.path of file here", RichTextBoxStreamType.RichText) '// change ".RichText" to ".PlainText" If needed.

Also, check if btnOk has been clicked before saving.

If SaveFile.ShowDialog = Windows.Forms.DialogResult.OK Then
            '// save :)
        End If

Edited by codeorder: '// save :)

0
'// TextBox.
        IO.File.WriteAllText("full.path of file here", TextBox1.Text)
        '// RichTextBox.
        RichTextBox1.SaveFile("full.path of file here", RichTextBoxStreamType.RichText) '// change ".RichText" to ".PlainText" If needed.

Also, check if btnOk has been clicked before saving.

If SaveFile.ShowDialog = Windows.Forms.DialogResult.OK Then
            '// save :)
        End If

Sorry but where should i put those codes?

0
With New SaveFileDialog
            .Filter = "Text Files (*.txt)|*.txt"
            .Title = "Save"
            If .ShowDialog = Windows.Forms.DialogResult.OK Then
                IO.File.WriteAllText(.FileName, TextBox1.Text)
                '// RichTextBox.
                'RichTextBox1.SaveFile(.FileName, RichTextBoxStreamType.RichText) '// change ".RichText" to ".PlainText" If needed.
            End If
        End With

If you still have this issue(should Not), reboot your system(could be an internal bug that needs to be squashed).

0

Thanks for input.
If thread solved, mark as Solved; best of luck and welcome to the forum.:)

Edited by codeorder: n/a

0

Well i solved it with the textbox but with the richtextbox not yet...

The new code is

Dim SaveFile As New SaveFileDialog
            SaveFile.FileName = ""
            SaveFile.Filter = "Text Files (*.txt)|*.txt"
            SaveFile.Title = "Save"
            SaveFile.ShowDialog()
            Try
                Dim Write As New IO.StreamWriter(SaveFile.FileName)
                Write.Write(TextBox1.Text)
                Write.Close()
            Catch ex As Exception
            End Try
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.