|
-
Dec 19th, 2005, 10:50 AM
#1
Thread Starter
Member
[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:
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
Microsoft Visual Studio.NET 2005 Express (freeeeeee for a limited time)

-
Dec 19th, 2005, 04:14 PM
#2
Thread Starter
Member
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)

-
Dec 19th, 2005, 05:53 PM
#3
Fanatic Member
Re: CSV File Manipulation
VB Code:
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
-
Dec 19th, 2005, 08:26 PM
#4
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|