Jump to content

Welcome to Geeks to Go - Register now for FREE

Geeks To Go is a helpful hub, where thousands of volunteer geeks quickly serve friendly answers and support. Check out the forums and get free advice from the experts. Register now to gain access to all of our features, it's FREE and only takes one minute. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more.

Create Account How it Works

Read .CSV file in Visual Basic

  • Please log in to reply



    New Member

  • Member
  • Pip
  • 3 posts
Hi there,

I'm trying to figure out how to read in a .CSV file into VB so that I can use the data. The field seperator being used is to be a comma. I want the VB to read in the data from the .CSV file row by row as each is a record of an event. I'm not a very experienced programmer so would appreciate any help on this topic. An example of the type of data being used is shown below:

Date Name Age Height
12/04/06 John Doe 36 176
14/04/06 Anne Other 28 159

  • 0


Hai Mac

Hai Mac


  • Member
  • PipPipPip
  • 260 posts
Hi triggerguard,
Your problem has two solutions, but I'll take you through the easier one. Firstly, define a Variant variable, let's say data.

Then open your CSV file for input as you would do for any other txt file. Read a line and store it in a string, like OneLine. Then do this:
 data = Split(OneLine,",")

The Split commands takes the string, cuts it ups according to what delimiter you chose (in this case comma) and stores the pieces in the variable as an array. So now data has become an array and contains following:

OneLine contains "12/04/06,John Doe,36,176"

data(0) will contain 12/04/06
data(1) will contain John Doe
data(2) will contain 36 etc.

These are all Variant. You might have to do some re-typing, if you want to.

Repeat the procedure with all other lines :blink:

If you have any further problems with my method, just tell me and I'll try to describe it better :whistling:
  • 0

Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP