Results 1 to 7 of 7

Thread: Write #

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837

    Write #

    anybody ever had any problems using the write # statement with a string that contained double quotes "?

    i see that it writes it to the file like..

    "this is ""my"" text"

    but when it goes to read it with input #, it fails to do so correctly
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  2. #2
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    Try saving it using the Print statement instead.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    MSDN says use write because it formats the data so that input can read it, otherwise if you use print you have to delimit it yourself

    "Note If, at some future time, you want to read the data from a file using the Input # statement, use the Write # statement instead of the Print # statement to write the data to the file. Using Write # ensures the integrity of each separate data field by properly delimiting it, so it can be read back in using Input #. Using Write # also ensures it can be correctly read in any locale."
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  4. #4
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    In the example you provided, print would be fine. I think the problem come in when you try to save comma or tab delimited file.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    837
    well that example wasn't completely accurate, really i need to save data that is maybe a page long with newlines in it and then later on in the file in need to save other things like numbers and stuff

    print/input isn't working either for this
    The human brain cannot hold all of the knowledge that exists in this world, but it can hold pointers to that knowledge.

  6. #6
    Lively Member
    Join Date
    Mar 2002
    Location
    Warrington, England
    Posts
    70
    Might help

    use chr$(34) instead of Quote

    Private Sub WriteFile()
    Dim F As Integer
    F = FreeFile
    Open "C:\test.txt" For Output As F
    Print #F, "Testing " & Chr$(34) & Chr$(34) & "OK" & Chr$(34) & Chr$(34)
    Close F

    End Sub


    Private Sub ReadFile()
    Dim F As Integer, str As String
    F = FreeFile
    Open "C:\test.txt" For Input As F
    While Not EOF(F)
    Line Input #F, str
    MsgBox str
    Wend
    Close F
    End Sub

    this reads double quotes OK

  7. #7
    Addicted Member Bazza81's Avatar
    Join Date
    Apr 2001
    Location
    Nottingham, UK
    Posts
    203
    Couldn't you write it into the text file this way:

    VB Code:
    1. Write #1, "This is " & Chr(34) & "My" & Chr(34) & " String"
    Who needs rhetorical questions anyway?


    Bazza NET - The place you want to be!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width