G
Gregg
Hello all,
I have been banging my head over a problem that I am having reading a
comma seperated file (CSV) that can contain from 1 to 10,000 records.
My code snipit is as follows:
**Start code snipit**
Dim strCustFullName as string
Dim strCustAddr1 as string
Dim strCustAddr2 as string
Dim strCustCity as string
Dim strCustState as string
Dim strCustZip as string
Dim strCustLastName as string
Dim strCustFirstName as string
FileOpen(1, filename, OpenMode.Input)
Do While Not EOF(1)
Input(1,strCustFullName)
Input(1,strCustAddr1)
Input(1,strCustAddr2)
Input(1,strCustCity)
Input(1,strCustState)
Input(1,strCustZip)
'I then proceed to open and SQL table and insert the record I have
just
'read.
'I then close the SQL table and loop back to the next record in the
'CSV file
Loop
**End Code Snipit**
My CSV file that I am reading from looks like this:
**Start CSV Example**
"LASTNAME,FIRSTNAME",ADDR1,ADDR2,CITY,STATE,ZIP
"LASTNAME,FIRSTNAME",ADDR1,ADDR2,CITY,STATE,ZIP
"LASTNAME,FIRSTNAME",ADDR1,ADDR2,CITY,STATE,ZIP
**End CSV Example**
ok, so what I end up with is:
strCustFullName = LASTNAME,FIRSTNAME
strCustAddr1 =ADDR1
strCustAddr2 = ADDR2
strCustCity = CITY
strCustState = STATE
strCustZip = ZIP
I then use a SPLIT on strCustFullName on the "," and assign the two
values to strCustLastName and strCustFirst Name.
All of this works perfectly....until today. Today, I get a CSV file
that
looks like this:
"LASTNAME,FIRSTNAME",ADDR1,ADDR2,CITY,STATE,ZIP
"LASTNAME,FIRSTNAME "NICKNAME""",ADDR1,ADDR2,CITY,STATE,ZIP
"LASTNAME,FIRSTNAME",ADDR1,ADDR2,CITY,STATE,ZIP
The second record causes my input loop to die and treats the NICKNAME
as
though it was going in the Addr1 column.
So, how do I handle my input statements to ignore the quotes around
the NICKNAME
or at least treat them like a string and not a field seperator. As a
side note,
yes, I know there are 3 quotes after the NICKNAME. I was told by the
programmer
that passes this file to me that is the proper format and I tested
that by
opening this file with Excel, and Excel read the data correctly and
displayed
it as LASTNAME,FIRSTNAME "NICKNAME" (which is how the data looks from
the
original source)
The full intent of this process is to create an SQL table with the
name of
the CSV file and then populate it with the records within the CSV
file.
Process it for a Crystal Report and then throw the CSV file and the
Table
away. All worked great until I hit this.
I would appreciate any help at all. Thanks so much
Gregg Cliburn
I have been banging my head over a problem that I am having reading a
comma seperated file (CSV) that can contain from 1 to 10,000 records.
My code snipit is as follows:
**Start code snipit**
Dim strCustFullName as string
Dim strCustAddr1 as string
Dim strCustAddr2 as string
Dim strCustCity as string
Dim strCustState as string
Dim strCustZip as string
Dim strCustLastName as string
Dim strCustFirstName as string
FileOpen(1, filename, OpenMode.Input)
Do While Not EOF(1)
Input(1,strCustFullName)
Input(1,strCustAddr1)
Input(1,strCustAddr2)
Input(1,strCustCity)
Input(1,strCustState)
Input(1,strCustZip)
'I then proceed to open and SQL table and insert the record I have
just
'read.
'I then close the SQL table and loop back to the next record in the
'CSV file
Loop
**End Code Snipit**
My CSV file that I am reading from looks like this:
**Start CSV Example**
"LASTNAME,FIRSTNAME",ADDR1,ADDR2,CITY,STATE,ZIP
"LASTNAME,FIRSTNAME",ADDR1,ADDR2,CITY,STATE,ZIP
"LASTNAME,FIRSTNAME",ADDR1,ADDR2,CITY,STATE,ZIP
**End CSV Example**
ok, so what I end up with is:
strCustFullName = LASTNAME,FIRSTNAME
strCustAddr1 =ADDR1
strCustAddr2 = ADDR2
strCustCity = CITY
strCustState = STATE
strCustZip = ZIP
I then use a SPLIT on strCustFullName on the "," and assign the two
values to strCustLastName and strCustFirst Name.
All of this works perfectly....until today. Today, I get a CSV file
that
looks like this:
"LASTNAME,FIRSTNAME",ADDR1,ADDR2,CITY,STATE,ZIP
"LASTNAME,FIRSTNAME "NICKNAME""",ADDR1,ADDR2,CITY,STATE,ZIP
"LASTNAME,FIRSTNAME",ADDR1,ADDR2,CITY,STATE,ZIP
The second record causes my input loop to die and treats the NICKNAME
as
though it was going in the Addr1 column.
So, how do I handle my input statements to ignore the quotes around
the NICKNAME
or at least treat them like a string and not a field seperator. As a
side note,
yes, I know there are 3 quotes after the NICKNAME. I was told by the
programmer
that passes this file to me that is the proper format and I tested
that by
opening this file with Excel, and Excel read the data correctly and
displayed
it as LASTNAME,FIRSTNAME "NICKNAME" (which is how the data looks from
the
original source)
The full intent of this process is to create an SQL table with the
name of
the CSV file and then populate it with the records within the CSV
file.
Process it for a Crystal Report and then throw the CSV file and the
Table
away. All worked great until I hit this.
I would appreciate any help at all. Thanks so much
Gregg Cliburn