Results 1 to 4 of 4

Thread: [RESOLVED] CSV File Manipulation

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    37

    Resolved [RESOLVED] CSV File Manipulation

    I have a CSV file I want to manipulate. I am dropping the csv into a list box, then going through line by line. I want to check a column for duplicates, and then:

    ---ex of the columns in csv file---
    Column1-----Column2--------Column3
    ------------------------------------
    004.tif----------9------------Keep
    005.tif---------10
    006.tif---------13
    004.tif---------15------------Bad
    007.tif---------17
    004.tif---------25------------Bad

    1.) if there is a duplicate (004.tif), go to the next column(2) and store the value in a field. Then if I come across another value which is a duplicate(4th line), check the other column and compare the 2 values, keeping the lowest, and flagging the higher one with a value in another column(3) so the result would look something like what you see above. I already have a function to put the csv into a list box:

    VB Code:
    1. Private Function CSV2ListBox()
    2.  
    3.         'This function gets all data from the specified csv file,
    4.         'and places it in row by row in a listbox
    5.  
    6.         Dim filetoread As String
    7.         Dim filestream As StreamReader
    8.         Dim readcontents As String
    9.  
    10.         Dim s As String
    11.         Dim a() As String
    12.         Dim j As Integer
    13.  
    14.         filetoread = System.IO.Path.GetFullPath("C:\len\test.csv")
    15.         filestream = File.OpenText(filetoread)
    16.         readcontents = filestream.ReadToEnd()
    17.  
    18.         s = readcontents
    19.  
    20.         lstResult.Items.Clear()
    21.  
    22.         a = s.Split(vbLf)
    23.  
    24.         For j = 0 To a.GetUpperBound(0) - 1
    25.             lstResult.Items.Add(a(j))
    26.         Next
    27.  
    28.     End Function

    Any help is greatly appreciated

    Microsoft Visual Studio.NET 2005 Express (freeeeeee for a limited time)

  2. #2

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    37

    Re: CSV File Manipulation

    Since the move from VB.net from Office Development Area, the response time has really gone down...

    Microsoft Visual Studio.NET 2005 Express (freeeeeee for a limited time)

  3. #3
    Fanatic Member BillBoeBaggins's Avatar
    Join Date
    Jan 2003
    Location
    in your database, dropping your tables.
    Posts
    628

    Re: CSV File Manipulation

    VB Code:
    1. Public Function PrevOccurrence(EndIndex as Integer) as Boolean
    2.   For I = 0 to EndIndex-1
    3.     If(lstItems.Item(I)=lstItems.Item(EndIndex))
    4.        PrevOccurrence=True
    5.        Exit Function
    6.     End If
    7.     PrevOccurrence=False
    8.   Next I
    9. End Function
    10.  
    11. If(PrevOccurrence(lstItems.ListIndex)) Then
    12.  'Do whatever to indicate it is already in the list
    13.  lstItems.Items(lstItems.ListIndex)=lstItems.Items(lstItems.ListIndex) & " BAD ITEM"
    14. End IF

  4. #4

    Thread Starter
    Member
    Join Date
    Aug 2005
    Posts
    37

    Re: CSV File Manipulation

    Thanks Bilbo, I ended up finding out a way similar to that, I will rate you anyway.

    If anyone wants to know how to do something along these lines, message me.

    Microsoft Visual Studio.NET 2005 Express (freeeeeee for a limited time)

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