PDA

Click to See Complete Forum and Search --> : [RESOLVED] CSV File Manipulation


jaya14
Dec 19th, 2005, 09:50 AM
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:


Private Function CSV2ListBox()

'This function gets all data from the specified csv file,
'and places it in row by row in a listbox

Dim filetoread As String
Dim filestream As StreamReader
Dim readcontents As String

Dim s As String
Dim a() As String
Dim j As Integer

filetoread = System.IO.Path.GetFullPath("C:\len\test.csv")
filestream = File.OpenText(filetoread)
readcontents = filestream.ReadToEnd()

s = readcontents

lstResult.Items.Clear()

a = s.Split(vbLf)

For j = 0 To a.GetUpperBound(0) - 1
lstResult.Items.Add(a(j))
Next

End Function


Any help is greatly appreciated

jaya14
Dec 19th, 2005, 03:14 PM
Since the move from VB.net from Office Development Area, the response time has really gone down...

BillBoeBaggins
Dec 19th, 2005, 04:53 PM
Public Function PrevOccurrence(EndIndex as Integer) as Boolean
For I = 0 to EndIndex-1
If(lstItems.Item(I)=lstItems.Item(EndIndex))
PrevOccurrence=True
Exit Function
End If
PrevOccurrence=False
Next I
End Function

If(PrevOccurrence(lstItems.ListIndex)) Then
'Do whatever to indicate it is already in the list
lstItems.Items(lstItems.ListIndex)=lstItems.Items(lstItems.ListIndex) & " BAD ITEM"
End IF

jaya14
Dec 19th, 2005, 07:26 PM
Thanks Bilbo, I ended up finding out a way similar to that, I will rate you anyway. :D

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