Results 1 to 3 of 3

Thread: Help with traversing through data

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Exclamation Help with traversing through data

    I'm having trouble with determining the best way to loop though a CSV file and break it into relevant segments.

    For example:
    The first line should read like the following:
    Column A,Column B,Column C, Column D, Column E, Column F
    Weight, Zone 2, Zone 3, Zone 9-10, Zone 11-12, Zone 13-16

    Each segment represents a column of data. So my problem is what is the cleanest and best way to break the preceding line and be able to read the revelent column of data? In other words information for 9 and 10 is in the D column, and information for 11 and 12 is in the E column, etc. Any help would be GREATLY appreciated.

    My initial attempt is posted below.

    Code:
    line = sr.readline
            headerArray = Split(line, ",")
            ReDim howMany(UBound(headerArray))
            For i = (LBound(headerArray) + 1) To UBound(headerArray) Step 1
                Dim tempArray
                tempArray = Split(Trim(headerArray(i)), " ")
    
    
                Dim j As Integer
                For j = LBound(tempArray) To UBound(tempArray) Step 1
                    Dim dashArray()
    
                    If (Mid(tempArray(j), 2, 1) = "-") Then
                        dashArray = Split(tempArray(j), "-")
                        ReDim Preserve headerArray(UBound(headerArray) + 1)
                        headerArray(j) = dashArray(0)
                        headerArray(j + 1) = dashArray(1)
                    End If
    
                    If (IsNumeric(tempArray(j))) Then
                        headerArray(i) = Format(Val(Trim(tempArray(j))), "000")
                    End If
                Next
            Next

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: Help with traversing through data

    Has anyone had a similiar problem like this one before? If so please let me know. Thank you.

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,222

    Re: Help with traversing through data

    You can use ADO.NET to read a CSV file straight into a DataTable. See www.connectionstrings.com for the details of the connection string and how you have to adjust your SQL code.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width