Results 1 to 14 of 14

Thread: Simple code.. What's wrong?

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Dec 2004
    Posts
    16

    Unhappy Simple code.. What's wrong?

    Ok.. What I'm trying to do is:

    1. open a log file - CHECK
    2. grab the first 15 characters of each line (an IP address) - CHECK
    3. bounce these first 15 off of my array to see if they are in it, if not, then record them in the array (arrIPs)
    4. Print the new IP.. only if it is one i haven't encountered thus far.


    The problem:
    It records the first IP and prints it out just fine, but then the second one prints in the text box multiple times.. as does the 3rd, 4th, etc..

    What am i doing wrong?? Any help at all is greatly appreciated. I'm a noob! But I don't wanna be!



    VB Code:
    1. Private Sub cmdLogalyze_Click()
    2. Dim arrIPs(1000) As Variant
    3. strwrap = Chr$(13) + Chr$(10)
    4. Chr$ (10)
    5. txtSimple = ""
    6. cd1.InitDir = "C:\Program Files\Apache Group\Apache2\logs"
    7. cd1.Filter = "Log Files (*.log)|*.log"
    8. cd1.ShowOpen
    9. If cd1.FileName = "" Then
    10. msg = MsgBox("No File Chosen.", vbInformation, "File Needed")
    11. Exit Sub
    12. End If
    13.  
    14.  
    15. Open cd1.FileName For Input As #1
    16. Do Until EOF(1)
    17. Line Input #1, strNewLine
    18. ' get the ip string from the start of the log
    19. strIP = (Mid(strNewLine, 1, 15))
    20.  
    21. 'loop through the array to see if the ip is in it
    22. For i = 1 To UBound(arrIPs)
    23. ' if it is, then go to the next line
    24. If strIP = arrIPs(i) Then
    25. GoTo skipwrite
    26. ' if not, then record it in the array
    27. Else
    28.  
    29. 'loop through array to find free spot for next ip
    30. For j = 1 To UBound(arrIPs)
    31. If arrIPs(j) = "" Then arrIPs(j) = strIP: GoTo PrintIP
    32. Next j
    33. End If
    34.  
    35. Next i
    36. PrintIP:
    37. txtSimple = txtSimple & strIP & strwrap
    38.  
    39. skipwrite:
    40. Loop
    41. Close #1
    42. End Sub
    Last edited by iqchicken; Jan 6th, 2005 at 08:36 PM. Reason: Simplification..
    -----------------------------------------------
    I am incapable of advanced reasoning.
    -----------------------------------------------

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