Wednesday, January 11, 2006

[VBScript] CSV to variables using Execute

Nico wrote, on microsoft.public.scripting.vbscript:
I need ASP to read the CSV file to read lines 2 on-wards and display it back to the user for verification. Each line has aprx 8 "," that control user properties.

I am looking for each line to be displayed back to the user without the "," so they can verify and write to an access db.

All i am looking for is a simple way to read the text display to the user for acceptance before writing it back to the db.
I wrote a response but thought a fuller treatment was in order, thus the following:

Data, stored in DEMO.CSV
Then the code which does nothing other than read the file, store the data in variables for each line of data, and for effect, echoes the first and last names And here's the results of the run, taken from SciTE's output window A possible extra step would be to read the header line, strips the spaces, build the "Dim" statements and execute them as well. Or maybe, create an instance of "Scripting.Dictionary" and use that. Or ... well, there must be more than two ways to do it, even in VBScript!

2 comments:

Anonymous said...

That's not good enough. What about true CSV as in
field1,"text,text\r\n,text",field3

Bruce M. Axtens said...

"True CSV"?? Given the wikipedia entry at en.wikipedia.org/wiki/.csv one man's CSV is another's TSV or QCSV.

As for "that's not good enough" are you offering to pay me to extend the functionality, or are you just irritated that I didn't foresee your needs? ;)