Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CSV files

Status
Not open for further replies.

hicks

Programmer
Sep 25, 2000
14
0
0
GB
Hi,

Can anyone help?
I have to write a few reports and produce them in CSV format.
Can anyone give me any help on how to achieve this?
I am using Oracle and VB.

Thanks
 
.csv is just comma delimited.
'Open a file for output. (MyFile.csv)
intFileNum = Freefile
Open "C:\MyFolder\MyFile.csv" For Output as intFileNum
strEOL = chr(13) + chr(10)
'the following would be in some kind of loop and 'Data()' is whatever your field(columns) are:
strTemp = Data(1) & "," & Data(2) & ","....... & strEOL
Print #intFileNum, strTemp
Close

that's it. the strEOL is a carrage return\Line feed at the end of each line.


 
The VB constant for strEOL is vbCrLf. _________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Can I offer another alternative using good old Scripting.FileSystemObject.

Code:
Dim FSO As New FileSystemObject
Dim tsOutput As TextStream
Dim astrData() As String  ' Array to hold data values
Set tsOutput = FSO.CreateTextFile(&quot;<csv file&quot;)

'# Perform the code to extract the data from Oracle here and perform a loop through the data populating the data array for each line.  The following line of code should be
placed in the loop to write the data to the csv file.

tsOutput.WriteLine Join(astrData,&quot;,&quot;)
' This will write a line containing all the information populated into the data array seperated by commas

tsOutput.Close

etc, etc,

HTH John Whyte
jwhyte@skipton.co.uk
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top