overwriting a text file with text

Post here about scripting and programming for HaloPC (audio, network, ai, etc.)
Post Reply
User avatar
Dagger13





Posts: 370
Joined: Wed Nov 22, 2006 12:37 pm

overwriting a text file with text

Post by Dagger13 »

well when ever i open a file and it contains a new line or when u press the
enter key that thing
i open files with the openfiledialog

when ever i overwrite a file those new line things come up as a box can somebody help
and im using vb 2005

heres a pic

Image
Last edited by Dagger13 on Sat Feb 02, 2008 11:47 am, edited 1 time in total.
Image(An Old one.)
OwnZ joO




Articulatist 500

Posts: 980
Joined: Thu Nov 10, 2005 4:24 pm

Post by OwnZ joO »

You need to explain better what you are trying to do, and what you did to accomplish it. How did you open the file(StreamWriter??) and what did you do?
User avatar
Dagger13





Posts: 370
Joined: Wed Nov 22, 2006 12:37 pm

Post by Dagger13 »

maybe now u will understand
Image(An Old one.)
User avatar
Anthony




Translator Connoisseur New Age ONI

Posts: 1001
Joined: Thu Jul 06, 2006 10:19 pm
Location: Whittier, CA
Contact:

Post by Anthony »

looks like a problem with the line terminator,

can you paste some of your saving code?
Patrickssj6




Pi Collaborator

Posts: 5426
Joined: Sat Jul 24, 2004 12:12 pm
Location: I'm a Paranoid
Contact:

Post by Patrickssj6 »

For saving try this...simple:

Code: Select all

FileOpen(1,*FILEPATHTOSAVETO*, OpenMode.Output)
PrintLine(1, *textfieldcontainingthetext*)
FileClose(1)
...left for good
User avatar
Dagger13





Posts: 370
Joined: Wed Nov 22, 2006 12:37 pm

Post by Dagger13 »

im using visual basic

this is what im using now

My.Computer.FileSystem.WriteAllText(filename, richtextbox1.Text, False)
Image(An Old one.)
User avatar
Anthony




Translator Connoisseur New Age ONI

Posts: 1001
Joined: Thu Jul 06, 2006 10:19 pm
Location: Whittier, CA
Contact:

Post by Anthony »

You can try this...

Code: Select all

richtextbox1.SaveFile(filename, RichTextBoxStreamType.PlainText)
User avatar
Prey




Connoisseur Snitch! Pyre Articulatist 500

Posts: 1026
Joined: Wed Dec 27, 2006 6:49 am
Location: UK
Contact:

Post by Prey »

It's just the way new lines are being saved by the two different methods.

The FileSystem method uses only the Line Feed (LF) control character, 0x0A, to represent a new line.. whereas notepad expects a Carriage Return (CR) control character, 0x0D, followed by a LF control character to represent a new line..

Without the CR, the LF goes unrecognised by Notepad, thus the unrecognised character..

The method Ant posted will use the CR+LF for new lines, so it'll "work" in Notepad.. but in future you're better off using the StreamWriter class for plain text operations.. in this case:

Code: Select all

        Dim sw As New StreamWriter(s.FileName)
        For i As Integer = 0 To RichTextBox1.Lines.Length - 1
            sw.WriteLine(RichTextBox1.Lines(i))
        Next
        sw.Close()
Although the rtb's built-in save method is obviously much more preferable here.
Halo 2 Prophet - Skin with ease with the simple 3D point and click interface.
Halo 3 Research Thread - Contribute to the research into Halo 3.
User avatar
Dagger13





Posts: 370
Joined: Wed Nov 22, 2006 12:37 pm

Post by Dagger13 »

lol thnx anthony i didnt even think of that

and thanks everybody else who commented
Image(An Old one.)
User avatar
Anthony




Translator Connoisseur New Age ONI

Posts: 1001
Joined: Thu Jul 06, 2006 10:19 pm
Location: Whittier, CA
Contact:

Post by Anthony »

Yeah no problem.

Next time if I were you, I would go with what prey suggested. That is the way I do it myself but since I figured you were probably new to VB I would help you in the simplest way possible
User avatar
Dagger13





Posts: 370
Joined: Wed Nov 22, 2006 12:37 pm

Post by Dagger13 »

im not new ive been on it for a few years i just never thought of doing that
Image(An Old one.)
Patrickssj6




Pi Collaborator

Posts: 5426
Joined: Sat Jul 24, 2004 12:12 pm
Location: I'm a Paranoid
Contact:

Post by Patrickssj6 »

Dagger13 wrote:im using visual basic
My code is also VB even though it looks kinda different :P
...left for good
Post Reply