|
-
February 16th, 2010, 11:06 AM
#1
Getting the three most common numbers from a file?!
Hey,
I have been a long time reader of this forum but only today have I finally had to resort to singing up and asking for help! I always see people giving very useful advice here so I am confident that you might be able to help.
Essentially, whenever my users who are logged in via a global module level variable enter a new form, their activity is "logged" in a textfile with their UserID as the name.txt and every time they visit a page it adds a new line to their log file with a number corresponding to the form they visited. For example, if they select "add a user" it will add the line "1" to their log file. Note: At the moment there is only 1 2 and 3 not 0.
I have got this far and I have got as far as creating an array which has:
Array(0) = NumberOfTimes 0 appears in the log file
Array(1) = NumberOfTimes 1 appears in the log file
etc etc
Therefore the output for this is
Msgbox(Array(0)) shows "0"
MsgBox(Array(1)) shows "4" for example and lets just say
MsgBox(Array(2)) shows "9" and
MsgBox(Array(3)) shows "1"
Therefore, finally (!) my problem is now finding which 3 are the top. I have tried various methods of sorting them but I just get "9, 4, 1, 0" rather than "2, 1, 3, 0"
If you understand I would greatly appreciate the help as I have been tearing my hair out for the past 2 days trying to do this! (By the way the end product for this is to show three links on the "welcome form" of the users 3 most visited forms)
Here is a pastebin of all the rubbish I have currently tried that hasn't worked! http://pastebin.com/f4030d95e
Again, thank you in advance for ANY help!
-
February 16th, 2010, 12:10 PM
#2
Re: Getting the three most common numbers from a file?!
For future I have worked this out, in case anyone wants it.
Code:
Test(0) = 4
Test(1) = 3
Test(2) = 123
Test(3) = 99
Dim TopThree(2) As Integer
Dim NewHigh As Integer
Dim Highest As Integer
Dim Count As Integer = 0
Dim Found As New ArrayList
For i = 0 To 3
Found.Add(Test(i))
Next i
' MsgBox(Found.Count)
'Dim TopThree(2) As Integer
For Index = 0 To UBound(Test)
If Test(Index) > Highest Then
Highest = Test(Index)
NewHigh = Index
End If
Next Index
'Found(Highest) = ""
Found.RemoveAt(NewHigh)
Found.Insert(NewHigh, 0)
'MsgBox(NewHigh)
TopThree(0) = NewHigh
'MsgBox(Found.Count)
Dim Highesta As Integer
For Indexa = 0 To 3
If Found(Indexa) > Highesta Then
Highesta = Found(Indexa)
NewHigh = Indexa
End If
Next Indexa
Found.RemoveAt(NewHigh)
Found.Insert(NewHigh, 0)
' MsgBox(NewHigh)
TopThree(1) = NewHigh
'MsgBox(Found.Count)
Dim Highestaa As Integer
For Indexaa = 0 To 3
If Found(Indexaa) > Highestaa Then
Highestaa = Found(Indexaa)
NewHigh = Indexaa
End If
Next Indexaa
Found.RemoveAt(NewHigh)
Found.Insert(NewHigh, 0)
' MsgBox(NewHigh)
TopThree(2) = NewHigh
ListBox1.Items.Add(TopThree(0))
ListBox1.Items.Add(TopThree(1))
ListBox1.Items.Add(TopThree(2))
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
|