By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,368 Members | 1,233 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,368 IT Pros & Developers. It's quick & easy.

file close

P: n/a
I have created a long string and want to save it to a file. I create the
file fine, but there are two additional characters at the end when I view it
in a hex editor "OD" and "OA".

Here is the code I have tried:

FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output,
OpenAccess.Write)
PrintLine(1, WholeString)
FileClose(1)

I can find no way to exclude this addition to my file. I tried changing to
FileOpen() with OpenMode.binary, but just got an error

Is there another way to close the file excluding these "OD" & "OA"
characters?

Thanks in advance,

Gator
Nov 21 '05 #1
Share this Question
Share on Google+
1 Reply

P: n/a
Here's a very basic example. This will always overwite the text in the file.
If you want it to APPEND then use 'Dim sw As New IO.StreamWriter(sFilename,
True)' instead of 'Dim sw As New IO.StreamWriter(sFilename)' (The keyword
TRUE means append).

Start a new Windows application

Add a button & a textbox to the form

Double-click the button & add this code:
-----------------------------------------

With SaveFileDialog1
.Filter = "Text Files(*.txt)|*.txt|All Files (*.*)|*.*"
.InitialDirectory =
Environment.GetFolderPath(Environment.SpecialFolde r.Desktop)
If .ShowDialog <> DialogResult.OK Then Exit Sub
End With
SaveFile(TextBox1.Text, "C:\SomeFile.txt")

Add this code:
---------------

Private Sub SaveFile(ByVal sText As String, ByVal sFilename As String)
Dim sw As New IO.StreamWriter(sFilename)
sw.WriteLine(sText)
sw.Flush()
sw.Close()
End Sub

I hope this helps

Crouchie1998
BA (HONS) MCP MCSE
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.