RSS

VBScript: importing and sorting CSV files

12 Jun

Okay, following my disconnect recordset posting, here is the code that I created to read CSV files to a disconnect recordset. You can then use sort on the records and manipulate the data as you like.

One thing to note, the CSV file should have quoted fields. The reason is that if you don’t quote all the fields items, some of contents of the field may contain comma (“,”), such as “Wong, Kelvin” and without this quotes, the comma may be interpreted as a delimiter in the script. By quoting every field it also makes the logic easier and more consistent.

This is one of the reasons why I almost always delimit my files with tilde (~), instead of other more common delimiters like comma or spaces.

Download code here: DisconnectRecordSet.vbs

Advertisements
 
2 Comments

Posted by on June 12, 2007 in Scripts, VBScripts

 

Tags:

2 responses to “VBScript: importing and sorting CSV files

  1. JB

    September 10, 2007 at 2:52 am

    Doesn’t work! Shit code, Erroes on Line 21, need to Dim fso. Have another go or give up scripting

     
  2. saltwetfish

    September 10, 2007 at 4:00 am

    My bad… I missed the line

    Set fso = Wscript.CreateObject(“Scripting.FileSystemObject”)

    I have updated the script. Note also that this will NOT work without modifications. You will need to have your CSV input file ready and also modify the section to add the appropriate files you need.

    Anyway, don’t need to beat yourself up too much over broken or bad codes. We all learn from our mistakes, that’s how great programmers are developed!

     

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: