Re: [2005] Array Duplicates
Loop thru the first one like you are. That is fine.
Put another loop inside of that loop that checks each in the list, adding +1 when it finds a match.
When it finishes, you will have a count of each word on the list
Re: [2005] Array Duplicates
Thanx for your advice. The problem is, I tried that - if you look closely I had a variable named SSDupsFound. The problem seems to be that it only checks once, but it does give me all the duplicate names, just not their numbers.
Any other ideas?
Re: [2005] Array Duplicates
Re: [2005] Array Duplicates
Looks like 2 loops to me, one in the calling routine and another inside the function which has been called from inside the first loop.
I did not look real closely but at a glance it appears that the return true is the problem. When it finds a dupe it exists the function rather than going through the rest of the items to see if there are any more instances of that item.
Re: [2005] Array Duplicates
OK, thanx DataMiser.
I have now replaced the Function with Sub.
I did this in there (it's basicall the same still):
Code:
Private Sub SSOrganiseList(ByVal arr As Array)
ReDim SSDup(arr.Length - 1)
For i As Integer = 0 To arr.Length - 1
If Not arr(i) Is Nothing Then
Dim l As Integer = Array.LastIndexOf(arr, arr(i))
If l <> i Then
SSDup(i) = l
End If
End If
Next
End Sub
Private Sub SSGetSubFileInfo(ByVal Path As String)
Dim stream_reader As IO.StreamReader
Dim i As Integer
'Dim j As Integer
stream_reader = New StreamReader(Path, True)
SSubText = stream_reader.ReadToEnd().Split(";")
stream_reader.Close()
ReDim SSFileSub(SSubText.Length - 1)
ReDim SSFileCount(SSubText.Length - 1)
For i = 0 To SSubText.Length - 1
SSFileSub(i) = SSubText(i).Substring(0, SSubText(i).LastIndexOf(" "))
SSFileCount(i) = SSubText(i).Substring(SSubText(i).LastIndexOf(" "), 2)
SSOrganiseList(SSFileSub)
Console.WriteLine(SSFileSub(SSDup(i)))
Console.WriteLine(SSFileCount(SSDup(SSDup(i))))
Next
End Sub
Now, it returns:
Code:
ASP 2 Advanced
2
ASP 2 Advanced
2
ASP 2 Advanced
2
ASP 2 Advanced
2
ASP 2 Advanced
2
ASP 2 Advanced
2
ASP 2 Advanced
5
ASP 2 Advanced
5
I can see it does get the associated numbers, but only for the one duplicated entry, not the secondone which is Dreamweaver.
I don't understand why I need to use more loops. With that logic, if I have 2 duplicated entrries, I ned 2 loops - in this case I have a possible 92 duplicated entries, so that means 92 loops? :confused:
Re: [2005] Array Duplicates
i was going to say this on vbforums, where the same question was asked http://www.vbforums.com/showthread.php?t=562886 . why allow duplicates at all? when someone clicks on one of the items just update the count when the click happens.
Re: [2005] Array Duplicates
Basically you need one loop that looks at every item in the array. Then you need the second loop inside the first. the second loop compares each item in the array to the item currently active in the outter loop. This will work for any number of dupes if done correctly but it does seem like an odd way to go about it.
As Oblio mentioned
I would strongly suggest updating the values in the array rather than writting dupes and trying to sort them out later.
Re: [2005] Array Duplicates
I just looked at the posts here in more detail. It appears that there are or could be many sessions written to that text file. If the intention is to keep each session recorded seperately but then be able to grab the totals for each item then what you may want to consider is a second array.
read the file into the array as you are doing now. Create a second array with the same structure.
Loop through the array item by item.
add another loop inside the first that will loop through the second array with each item in the first array to see if it exists in the new array. If it does update that value in the new array. If it does not then add the item to the new array. when your outter loop is completed you will have a new array with no dupes and an accurate count for each item.
If you do not need to store each session seperately then I would simply read the file into an array at the start of the program, update that array with each click and then over write the file with the updated values which would contain no dupes.
Re: [2005] Array Duplicates
How about try this its a function, i made to get rid of duplicates of a simple way all it does its recives 2 parameters the combobox and the string to add on it. if the function returns true the that means that string its actually on the combobox list., in this case it wont try to add it, if false ill add it.
of this simple way u wont have duplicates on ur combobox!.
Code:
Function Duplicated(ByVal Item As String, ByVal CList As ComboBox) As Boolean
Dim c As Integer
For c = 0 To CList.Items.Count - 1
If Item = CList.Items.Item(c) Then
Return True
Exit For
End If
Next c
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Duplicated(TextBox1.Text, ComboBox1) = False Then
ComboBox1.Items.Add(TextBox1.Text)
End If
End Sub
Hoppe it helps you
Re: [2005] Array Duplicates
Really should create a class with two variables, mCLASS and mRANK
Then, in your click event, search thru the list for the class. If found, add 1, if not call NEW and add it to the list with the mRANK of 1
Then you will be able to get direct answers.