New problem when import .CSV file which is exported by Outlook

LoveVB99
06-12-2003, 03:58 AM
I write an application to organize my contacts, so I need to import contacts from Outlook or other applications, when I use Outlook to export some contacts to .csv file and try to import it to my application, I found some special record will cause some problem when importing, and I can't find any description on this forum.

Suppose the .csv file which is exported by Outlook is as follows:
====================================================================== ========
"Title","First Name","Middle Name","Last Name","Suffix","Company","Department","Job Title","Business Street","Business Street 2","Business Street 3","Business City","Business State","Business Postal Code","Business Country","Home Street","Home Street 2","Home Street 3","Home City","Home State","Home Postal Code","Home Country","Other Street","Other Street 2","Other Street 3","Other City","Other State","Other Postal Code","Other Country","Assistant's Phone","Business Fax","Business Phone","Business Phone 2","Callback","Car Phone","Company Main Phone","Home Fax","Home Phone","Home Phone 2","ISDN","Mobile Phone","Other Fax","Other Phone","Pager","Primary Phone","Radio Phone","TTY/TDD Phone","Telex","Account","Anniversary","Assistant's Name","Billing Information","Birthday","Categories","Children","Directory Server","E-mail Address","E-mail Display Name","E-mail 2 Address","E-mail 2 Display Name","E-mail 3 Address","E-mail 3 Display Name","Gender","Government ID Number","Hobby","Initials","Internet Free Busy","Keywords","Language","Location","Manager's Name","Mileage","Notes","Office Location","Organizational ID Number","PO Box","Priority","Private","Profession","Referred By","Sensitivity","Spouse","User 1","User 2","User 3","User 4","Web Page"
"","","","Test1","","","","",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"","0/0/00",,,"0/0/00",,,,,,,,,,"Unspecified",,,"T.",,"","","",,,"",,,,"Normal","False",,,"Normal"
"","","","zTest","","","","",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"","0/0/00",,,"0/0/00",,,,,,,,,,"Unspecified",,,"z.",,"","","",,,"Line1
line2
line3",,,,"Normal","False",,,"Normal",,,,,,"http://aaa"
====================================================================== ========

The first line is field name in Outlook, there two contacts in outlook, one is "Test1", the other is "zTest", the number of field is 87, for the first record "Test1", there are only 81 field since Test1's "Spouse","User 1","User 2","User 3","User 4" and "Web Page" is Empty value so Outlook don't export it. for the second record "zTest", there are 87 field but the "Notes" have some CRLF (Line1 Line2 Line3);

I don't know how to import this file correctly, if I use "input #" to read the record to 87 variants, 6 fields of the second record will be put to the first record since the first record only have 81 fiels. if I use "line input #", it will split the second record to 3 record since there are CRLF between "Line1" and "line2", "line2" and "line3 ..."

Any help would be appreciated

JordanChris
06-12-2003, 04:25 AM
The end of a record is always a " mark.
If you read the input file line by line, and the last character is not a ", then you know that the field has not yet ended. So you add a vbCRLF to the line, read the next line and add it to the first.

LoveVB99
06-13-2003, 12:15 AM
Thanks for JordanChris's message.

The .CSV file which is exported by Outlook always has a " mark at the end of each record, but other software such as Outlook Express, export a csv file without " mark at each record, unless the exported string contains "," or "CRLF", it will be quoted by "

But your answer give me valued advice so that I can deal with different .csv file, thanks a lot.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum