Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem data in output csv file

Status
Not open for further replies.

GJP55

Technical User
Joined
Feb 2, 2003
Messages
220
Location
GB
I am working on code at the moment to read a csv file, remove a speific character in each row and then write the line into a new file. The code runs fine except that when I look at the data in the new file it shows like this:

??????????????????????????????????????????????????


Does anybody know what I am doing wrong ??
Thanks

Code:

Private Sub ChangeFile()

Dim iFile As Integer
Dim oFile As Integer
Dim strTemp As String
Dim NewLine As String

iFile = FreeFile
Open "C:\Read.csv" For Input As #iFile

oFile = FreeFile
Open "C:\Write.csv" For Output As #oFile

Do While Not EOF(iFile)

Line Input #iFile, strTemp
NewLine = Replace(strTemp, Chr(34), "")
Print #oFile, NewLine

Loop

Close #iFile
Close #oFile

End Sub
 
How was the CSV created?
Is it perchance Unicode encoded?

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Take a look at the FileSystemObject (Add Referance Microsoft Scripting Runtime [scrrun.dll]).

Code:
    'TristateUseDefault = Opens the file using the system default.
    'TristateTrue = Opens the file as Unicode.
    'TristateFalse = Opens the file as ASCII.
    Dim Fso As FileSystemObject
    Dim Source As TextStream
    Dim Dest As TextStream
    Set Fso = New FileSystemObject
    Set Source = Fso.OpenTextFile("FullPathToSourceFile.csv", ForReading, False, TristateFalse)
    Set Dest = Fso.OpenTextFile("FullPathToDestinationFile.csv", ForWriting, True, TristateFalse)
    Do Until Source.AtEndOfStream = True
        Dest.WriteLine Replace(Source.ReadLine, Chr(34), "")
    Loop
    Source.Close
    Dest.Close

"If I were to wake up with my head sewn to the carpet, I wouldn't be more surprised than I am right now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top