Salt * Wet * Bytes

June 12, 2007

VBScript: importing and sorting CSV files

Filed under: AdminScripts — saltwetfish @ 2:41 am

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

2 Comments »

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

    Comment by JB — September 10, 2007 @ 2:52 am | Reply

  2. 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!

    Comment by saltwetfish — September 10, 2007 @ 4:00 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.