Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Reading Excel CSV with VB6

I have a program that read a fixed length record file that is now being supplied as a comma delimited csv. I need the data copied to an Access mdb and the program would do that. What is the best VB6 method for reading the csv and parsing the field now that they have commas and quotes?
Thanks
[298 byte] By [Don] at [2007-11-11 8:13:18]
# 1 Re: Reading Excel CSV with VB6
If the individual fields do not contain commas, e.g.:

"Field 1","Field 2","Field 3", etc.

you can simply use VB's Split function:

Dim Fields() As String
Fields = Split(Text, ",")
' Fields(0) = "Field 1"
' Fields(1) = "Field 2"
' Fields(2) = "Field 3"
' etc.

If you then want to remove the quotes, you can use VB's Replace function.

If, however, the field data may include commas, you'll have to write (or steal ;-) a parsing routine. Try Googling for "vb csv quotes commas (http://www.google.com/search?q=vb+csv+quotes+commas)".
Phil Weber at 2007-11-11 17:25:46 >
# 2 Re: Reading Excel CSV with VB6
Several ways you can handle this. You can use Phil's suggestion, or you can use data access.

Dim cnn As New ADODB.Connection
Dim rs As New ADODB.Recordset

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & "C:\Documents and Settings\...\My Documents\My Database\Text;" & _
"Extended Properties=""Text;HDR=No;"""

rs.Open "Select * from Records.csv", cnn, adOpenStatic, adLockReadOnly


You can also import directly using SQL if that is what you need to do.
pclement at 2007-11-11 17:26:48 >