tags:

views:

59

answers:

4

Hey, I have this file. It stores a names, a project, the week that they are storing the data for and hours spent on project. here is an example

"James","Project5","15/05/2010","3"
"Matt","Project1","01/05/2010","5"
"Ellie","Project5","24/04/2010","1"
"Ellie","Project2","10/05/2010","3"
"Matt","Project3","03/05/2010","4"

I need to print it on the form without quotes. There it should only show the name once and then just display projects under the name. I've looked tihs up and the split function seems interesting

any help would be good.

+1  A: 

Microsoft has a CSV ADO provider. I think it is installed along with the rest of ADO. This is exactly the format it was designed to read.

See http://www.vb-helper.com/howto_ado_load_csv.html for a VB sample.

Tom Cabanski
That's unnecessarily complex. VB6's intrinsic file I/O functions are all you need.
raven
+1  A: 

Do I understand you correctly in that you want to keep track of the names entered and thus re-order the data that way? Why not just read the data into a list of some new type that has the name, project, and other information and then sort that before printing it?


While the Dictionary solution is simpler, this may be a better solution if you are OK with building a class and implementing the IComparer so that you could sort the list to get this done pretty easily.

JB King
That would be a better way to do it, but I dont think I have the programing skills to pull it off.
Andeeh
+2  A: 

Create a Dictionary object and then put everything you find for a given name into one dictionary entry.

Then in a second iteration print all that out.

Foxfire
A: 

You could read each line, strip out the quotes, split on the comma, then process the array of data you would be left with:

Dim filenum As Integer
Dim inputLine As String
Dim data() As String

filenum = FreeFile
Open "U:\test.txt" For Input As #filenum
Do While Not EOF(filenum)
  Line Input #filenum, inputLine
  inputLine = Replace(inputLine, Chr(34), vbNullString)
  data = Split(inputLine, ",")
  Debug.Print data(0), data(1), data(2), data(3)
Loop
Close #filenum

Or you could have the Input command strip the quotes, and read the data into variables:

Dim filenum As Integer
Dim name As String, project As String, dat As String, hours As String

filenum = FreeFile
Open "U:\test.txt" For Input As #filenum
Do While Not EOF(filenum)
  Input #filenum, name, project, dat, hours
  Debug.Print name, project, dat, hours
Loop
Close #filenum
raven