writing a text in a file in vb.net not working properly

S

sethuganesh

hi,

i am not able to write a text properly in a text file in vb.net.below
is the code that i have written.

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim counter As Integer
FileOpen(1, "c:\sample.txt", OpenMode.Random, , , 50)
For Counter = 1 To 5
FilePut(1, "ganesh", counter)
Next Counter
FileClose(1)
End Sub.
The output of the code is " ganesh
 ganesh  ganesh
 ganesh
 ganesh"

i am not able to understand why this symbol gets displayed "".is there
any solution for this ?

Thanks,
Ganesh
 
A

Andrew Morton

i am not able to write a text properly in a text file in vb.net.below
is the code that i have written.
i am not able to understand why this symbol gets displayed "".is
there any solution for this ?

FilePut isn't intended for writing text files - it's more for writing to
files that will be read back with FileGet. For VB functions to do what
you appear to want, see the docs for Write and WriteLine.

Andrew
 
S

sethuganesh

hi,

i am using FileGet function to read the file.but i want to know why
the symbol "  " gets displayed while writing into file.

Thanks,
Ganesh
 
A

Andrew Morton

i am using FileGet function to read the file.but i want to know why
the symbol "  " gets displayed while writing into file.

Read the docs for FilePut for clues, e.g.
"If the variable being written is a string, FilePut writes a two-byte
descriptor containing the string length, and then writes the data that
goes into the variable. Therefore, the record length specified by the
RecordLength clause in the FileOpen function must be at least two bytes
greater than the actual length of the string."

And, knowing that it isn't actually a text file, you should be using a
hex editor to examine the content of the file.

HTH

Andrew
 

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