Bob Schneider
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:
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
ASKER
HOw do I generate a comma delimited file with classic asp? Just replace vbTab with "," ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
EXPERT CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
"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.
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.
txt file Is usually tab delimited but make it comma delimited and its a csv file