file close

L

LeatherGator

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
 
C

Crouchie1998

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.SpecialFolder.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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top