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
Printable View
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
Try saving it using the Print statement instead.
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."
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.
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
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
Couldn't you write it into the text file this way:
VB Code:
Write #1, "This is " & Chr(34) & "My" & Chr(34) & " String"