Home All Groups Group Topic Archive Search About

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

Author
15 Jun 2006 10:07 AM
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

Author
15 Jun 2006 10:27 AM
Andrew Morton
sethugan***@gmail.com wrote:
>  i am not able to write a text properly in a text file in vb.net.below
> is the code that i have written.
<snip code using FilePut>
> 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
Author
15 Jun 2006 12:36 PM
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


Andrew Morton wrote:
Show quoteHide quote
> sethugan***@gmail.com wrote:
> >  i am not able to write a text properly in a text file in vb.net.below
> > is the code that i have written.
> <snip code using FilePut>
> > 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
Author
15 Jun 2006 1:41 PM
Andrew Morton
sethugan***@gmail.com wrote:
>  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