option explicit dim csvfile set csvfile = new clsCSVWriter csvfile.OpenFile "test.csv",csvfile.Overwrite ' Overwrite csvfile.Delimiter = ";" '~ csvfile.Quote = "'" csvfile.WriteRawLine("# Dies ist ein Kommentar") csvfile.WriteRawLine("# Created with MSXFAQ.CSVWriter") csvfile.AddHeader "field1" : csvfile.AddHeader "field2" : csvfile.AddHeader "field3" csvfile.WriteHeader("# Field: ") ' Ab hier dann csvfile.StartLine csvfile.AddField "field1","Feld1content" csvfile.AddField "field2","Feld2content" csvfile.AddField "field3","Feld3content" csvfile.Writeline 'Zeile rausschreiben class clsCSVWriter ' Class to write generic CSVFiles ' Version 1.1 WriteHeader + Prefix, WriteRawLine ' Version 1.0 Initial Version ' Last Modified: 22. Nov 2006 ' Pending: Quotataion of '"'-Character in Data !! private csvfilename, csvfs, csvfile, chrDelimiter, chrQuote, strline private dictLine private Sub Class_Initialize chrDelimiter =";" : chrQuote = """" : csvfilename = "" set dictLine = createobject("scripting.dictionary") End Sub public property let Delimiter (wert) ' Konfigure the delimiter. Default is ";" chrDelimiter =wert end property public property let Quote(wert) ' Konfigure the sting enquoting. Default is " chrQuote = wert end property public property get Overwrite ' Contant für Filemode Overwrite = 2 end property public property get Append ' Contant für Filemode Overwrite = 8 end property sub OpenFile(wert,intFileMode) ' Open and start a new CSV-File if csvfilename <> "" then 'Close existing debug file csvfile.close : csvfile = nothing : csvfs = nothing end if csvfilename = wert ' open debug file Set csvfs = CreateObject("Scripting.FileSystemObject") Set csvfile = csvfs.OpenTextFile(csvfilename, intFileMode, True) end sub sub AddHeader(strvalue) ' Add a new column to the csv dataset if dictLine.exists(strvalue) then objDebug.writeln "CSVWriter: duplicate Header definition:" & strValue, 1 else dictLine.add strvalue, empty end if end sub Sub WriteHeader(strPrefix) ' Write the current Header Definition to the file. optional with a prefix ' Prefix can be used to fake IISLogs with "# Field: " dim key, strline strline = "" for each key in dictLine.keys if strline <> "" then strline = strline & chrDelimiter end if strline = strline & chrQuote & cstr(key) & chrQuote next csvfile.WriteLine(strPrefix & strline) End Sub sub AddField(strfieldname,strvalue) ' add a valuue together with the field name if dictLine.exists(strfieldname) then dictLine.item(strfieldname) = strvalue else objDebug.writeln "CSVWriter: Field not declared:" & strFieldname, 1 end if end sub Sub WriteLine ' Write the current filled fields to the disk and starte a new line dim key, strline strline = "" for each key in dictLine.keys if strline <> "" then strline = strline & chrDelimiter end if strline = strline & chrQuote & dictLine(key) & chrQuote dictLine.item(key) = empty next csvfile.WriteLine(strline) End Sub Sub WriteRawLine(strLine) ' Write line without any formatting etc. Ideal für comments and other custom output csvfile.WriteLine(strline) End Sub sub StartLine ' Start a new line. Remove all existing data of the current line dim key, strline strline = "" for each key in dictLine.keys dictLine.item(key) = empty next End Sub end class