Wrox Programmer Forums
|
Beginning VB 6 For coders who are new to Visual Basic, working in VB version 6 (not .NET).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning VB 6 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 8th, 2005, 06:04 PM
Registered User
 
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Reading a csv file

I have a comma delimited file in this format
value1, value2, value3, value4
value1, value2, value3, value4
value1, value2, value3, value4

How can I open the file and read the data into fields? i.e,
lastName, firstName, phoneNo, Age

I've found many sample but they all cover reading the textfile,
I need to know how to read the text file but split the line or
read each value into a field.

Any help would be deeply appreciated. Thanks.


 
Old February 9th, 2005, 10:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

hi there..

if you already found out how to read the file, read every line and then use the split function to get every value...

HTH

Gonzalo
 
Old February 9th, 2005, 12:39 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

In addition to using split, you can use a loop. Use InStr() to find the location of the first comma.
Put all upt to that point-1 into the first field [fld = Left$(strStuff, CmaLoc -1)].
Find the next comma.
Read all into the next field from the previous comma's location + 1 to the current comma's location - 1.
Keep doing this till you run out of commas, finally using all of the end of the string following the last comma.





Similar Threads
Thread Thread Starter Forum Replies Last Post
parse a csv file shinny Pro Java 4 September 11th, 2006 06:26 AM
Getting .csv file name from the server langer123 Classic ASP Basics 0 April 13th, 2005 09:14 AM
Connectiong to .csv file langer123 Classic ASP Basics 1 March 31st, 2005 09:52 AM
Reading a .csv file Dave Brown Beginning PHP 1 March 1st, 2005 10:57 AM
Reading CSV in DataReader salimgbelim ADO.NET 0 November 3rd, 2003 07:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.