Link to home
Start Free TrialLog in
Avatar of Bob Schneider
Bob SchneiderFlag for United States of America

asked on

How do I create a *.csv file

I have a classic asp site that currently creates a plain text file from a database.  The end user then has to turn it into a *.csv file.  Is there a way to create the *.csv file directly?

Here is how I create the file:
Set fs=Server.CreateObject("Scripting.FileSystemObject")
sFileName = "C:\inetpub\h51web\gopherstateevents\dwnlds\athl-net_" & sMeetName & "_" & Year(dMeetDate) & ".txt"
Set fname=fs.CreateTextFile(sFileName, True)

fname.WriteLine(sMeetName)
fname.WriteLine(dMeetDate)
fname.WriteLine(sRaceName)
fname.WriteLine(iDist & " " & sUnits)

fname.WriteBlankLines(1)

fname.WriteLine("PLACE" & vbTab & "FIRST" & vbTab & "LAST" & vbTab & "GENDER" & vbTab & "GR" & vbTab & "TEAM" & vbTab & "TIME")
For i = 0 to UBound(RsltsArr, 2)
    fname.WriteLine(i + 1 & vbTab & RsltsArr(0, i) & vbTab & RsltsArr(1, i) & vbTab & RsltsArr(2, i) & vbTab & RsltsArr(3, i) & vbTab & RsltsArr(4, i) & vbTab & RsltsArr(5, i))
Next

fname.Close
Set fname=nothing
Set fs=nothing

Open in new window

Avatar of MacNuttin
MacNuttin
Flag of United States of America image

Just change the extension to .csv  

txt file Is usually tab delimited but make it comma delimited and its a csv file
Avatar of Bob Schneider

ASKER

HOw do I generate a comma delimited file with classic asp?  Just replace vbTab with "," ?
ASKER CERTIFIED SOLUTION
Avatar of MacNuttin
MacNuttin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
EXPERT CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
"CSV" stands for "Comma separated values". Very simple, its just a number of fields, separated by commas. You seem to be outputting fields separated by tabs. Just use commas instead, and rename the file with a .CSV extension.
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

That will work until you have a text field with a comma in the data.  If that is possible, you should also add double quotes to the values but that causes another issue if you can have double quotes in the data.