shamster
(Lurker)
2006-12-28 10:49 AM
writing to a csv file

Hi guys, first post so go easy on me

I had a search for the answer but couldn't find it

basically I have a login script which I have inherited, I want it to write an entry into a csv file to update it with some info

what commmand do you need to use?


Mart
(KiX Supporter)
2006-12-28 11:37 AM
Re: writing to a csv file

Hi and welcome to the board.

You could use writeline to write to a csv file.

Code:
Break on
;
;Open the file.
$rc = Open (1, "c:\somefile.csv", 5)
;
;Write stuff to the file.
$rc = WriteLine (1, "some data to write to the csv file" + @CRLF)
;
;Close the file.
$rc = Close (1)


Glenn BarnasAdministrator
(KiX Supporter)
2006-12-28 03:09 PM
Re: writing to a csv file

The CSV UDF assures a properly formatted CSV record. Send it an array, you get a CSV string. Send it a CSV string, you get an array.

So, if you load your data into an array, it becomes this simple:
Code:
$array = 'data', 'data', 'more data' ...
$RC = RedirectOutput('your_log.csv')
CSV($array) ; csv string is not captured, just written to StdOut
$RC = RedirectOutput('')


Glenn


Sealeopard
(KiX Master)
2006-12-29 01:43 AM
Re: writing to a csv file

However, you will have to ensure that you send in the correct amount of data. A CSV file is essentially a table where the columns are being separated by commas (enclose strings with quotation marks in case they could contain commas), and each line represents a row.