Results 1 to 8 of 8

Thread: [RESOLVED] Even harder sorting array stuff

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Resolved [RESOLVED] Even harder sorting array stuff

    Old Post

    Thank you for helping me with the old problem, now i have an even harder new one.

    This time i need to count how many times an IP accessed a file.

    So for example

    IP_array(0)="192.168.1.1"
    IP_array(1)="192.168.1.1"
    IP_array(2)="192.168.1.1"
    IP_array(3)="192.168.1.2"
    IP_array(4)="192.168.1.2"
    IP_array(5)="192.168.1.1"
    IP_array(6)="192.168.1.1"
    IP_array(7)="192.168.1.3"
    IP_array(8)="192.168.1.1"

    File_array(0)="Bob" 'Index is reletive to above
    File_array(1)="Bob"
    File_array(2)="Fred"
    File_array(3)="Bob"
    File_array(4)="John"
    File_array(5)="Bob"
    File_array(6)="John"
    File_array(7)="Bob"
    File_array(8)="Bob"

    'All Indexes are reletive
    Frequency_IP_File_array(0)="4" 'Bob by 192.168.1.1
    Frequency_IP_File_array(1)="4" 'Bob by 192.168.1.1
    Frequency_IP_File_array(2)="1" 'Fred by 192.168.1.1
    Frequency_IP_File_array(3)="1" 'Bob by 192.168.1.2
    Frequency_IP_File_array(4)="1" 'John by 192.168.1.2
    Frequency_IP_File_array(5)="4" 'Bob by 192.168.1.1
    Frequency_IP_File_array(6)="1" 'John by 192.168.1.1
    Frequency_IP_File_array(7)="1" 'Bob by 192.168.1.3
    Frequency_IP_File_array(8)="4" 'Bob by 192.168.1.1

    Would anyone have any idea how to get around this one??? I don't have an idea...

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Even harder sorting array stuff

    Why don't you store your data in a database ?

    It is so much easyer to just write a select query to return the values you need

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Even harder sorting array stuff

    I dunno how to make it into a database, it's just something i've never been taught, started to think about doing it though.

    Got any good tutorials for a beginner. I know a tiny bit of SQL, but not how to tmake VB & databases talk.

  4. #4
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: Even harder sorting array stuff

    Here's an example how to connecto to an Access database:
    http://vbforums.com/showthread.php?t=438957

    But this example shows how to make a log-in where the username and password is stored in the database

  5. #5
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: Even harder sorting array stuff

    If your gonna expand your use of collection in your other thread then use name & " by " & IP as the key rather than just IP... handle the error by incrementing the value of the collection item rather than just skipping it (which just tests existence of key).

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Even harder sorting array stuff

    Got it, i'm busy again with assignments, but will try it some time on the weekend.

    Thanks for your help

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Even harder sorting array stuff

    This is sort of the forum's "standard" ADO tutorial. It starts with the basics and gives you enough to play with SQL statements.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2005
    Posts
    540

    Re: Even harder sorting array stuff

    Thanks guys.

    I ended up solving it

    I didn't even use a database.

    Code:
    Dim Sorted_IP_File_() As String
    Dim Total_IP_File_() As Long
    Dim File_() As String
    Dim IPs() As String
    
    
    Private Sub GetUniqueColValuesIPFiles()
    
    Dim x As Long
    Dim y As Long
    Dim col As Collection
    
    Set col = New Collection
    For x = 0 To UBound(IPs)
    On Error Resume Next
    col.Add IPs(x) & "*" & File_(x), IPs(x) & "*" & File_(x)
    Next
    
    ReDim Total_IP_File_(col.Count) As Long
    For x = 0 To UBound(IPs)
    For y = 1 To col.Count
    If col.Item(y) = IPs(x) & "*" & File_(x) Then
    Total_IP_File_(y) = Total_IP_File_(y) + 1
    Exit For
    End If
    Next
    Next
    
    ReDim Sorted_IP_File_(col.Count)
    
    For y = 1 To col.Count
    Sorted_IP_File_(y) = col.Item(y)
    'Debug.Print Sorted_IP_File_(y), Total_IP_(y)
    Next
    
    End Sub
    Instead of using all fancy array logic, or database queries, all's i did was pass the IP address and the File that was accessed by that IP, i seperated both of those with a star (*). That way if i ever needed to split it back up i could, since i will never get an IP address or filename with a star in it.

    Thanks for you help.

    The database stuff looks heaps complicated and i don't think i'd need it for this program (since it only creates reports from a log file). But it is useful and now i can start to learn it.

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