Home: Tip of The Day: Creating Comma Delimited Files: 
Tip of The Day - Creating Comma Delimited Files

There are two main ways you can output comma delimited files. First let's create and array:

set $Colours=$New.Array();
$Colours.Add(NAME,"Green", CODE,"G");
$Colours.Add(NAME,"Red", CODE,"R");
$Colours.Add(NAME,"Multi-Coloured", CODE,"M");
$Colours.Add(NAME,"Light "+$Quote+"Red"+$Quote,CODE,"LR");

Let's make a text area the user can cut and paste out of:

<FORM><TEXTAREA ROWS=5 COLS=80>
forevery($Colour,$Colours)
{ $Quote;$Colour.NAME.Replace($Quote,"'");$Quote; ",";
$Quote;$Colour.CODE.Replace($Quote,"'");$Quote; $NewLine;
}
</TEXTAREA></FORM>

Let's make a file and link the user can click on:

set $Buffer=$New.StringBuffer();
forevery($Colour,$Colours)
{ $Buffer.Append($Quote+$Colour.NAME.Replace($Quote,"'")+$Quote+",");
$Buffer.Append($Quote+$Colour.CODE.Replace($Quote,"'")+$Quote+$NewLine);
}
createdatafile("CDFTest.cdf","Data",$Buffer);
datafilelink("CDFTest.cdf","Test File");
Download  |  Tutorial  |  Documentation  |  Pricing  |  Contact