Looping Through Data (CSV)

DarrenK

Member
Joined
Sep 9, 2008
Messages
10
Programming Experience
Beginner
Hi

I'm pretty sure this is a simple problem but it's one of those where I've been banging my head on it all day and I think I just can't see the wood for the trees.

I have a csv file with data in it in the format...

VB.NET:
EVENT|RUNNER|ODDS
1 - 2 - 1
1 - 2 - 3
1 - 2 - 5
1 - 3 - 6
1 - 3 - 5
2 - 3 - 4
2 - 3 - 5
2 - 4 - 7
2 - 4 - 5

etc...

So basically the data contains events, runners and odds. I'm looping through and assigning the variables to the relevant object propeties, alls fine.

The problem comes when I'm checking the next runner id (or event id) to see if it's changed so that I know to create a new object. Well in checking that the id has changed I've already moved one record too far so every time I'm changing to a new id I'm losing one record.

Hope that makes sense.

As I say I'm sure it's a simple solution but I can't for the life of me figure it out.

Hope you can help as I'm losing hair by the second over here. :eek:

Thanks

Darren
 
Just read all the data for a row first and test it first, before you put it anywhere permanent. In pseudo-code:
VB.NET:
For each line in the file
    Read the line and break it into parts
    Test each part as needed

    If the ID has changed
        Create a new object

    Populate the object
 
Thanks for the response.

That's kind of the approach I've been taking all day but I can't seem to get it figured. The problem is as I mentioned above, by the time you've checked the next line to see if the id is changed you've gone to far and the variables you've loaded in your...

VB.NET:
    Read the line and break it into parts
    Test each part as needed

contains the wrong line. Does that make sense? Maybe I'm not explaining it well. Or maybe I'm over complicating it for myself.

DK
 
Wouldn't a change mean that current line was different from previous line?
 
Hi JohnH

Yes and that's exactly the problem I'm having. By the time you've moved to the next line to see that it's changed you've gone 1 line to far.

DarrenK
 
What has next line got to do with anything? You create a new object when current is new, current is new if it is different from historical data, right?
 
Back
Top