Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

Read .CSV file in Visual Basic


  • Please log in to reply

#1
triggerguard

triggerguard

    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

Cheers
  • 0

Advertisements


#2
Hai Mac

Hai Mac

    Member

  • 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