|
-
Jan 6th, 2005, 08:34 PM
#1
Thread Starter
Junior Member
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:
Private Sub cmdLogalyze_Click()
Dim arrIPs(1000) As Variant
strwrap = Chr$(13) + Chr$(10)
Chr$ (10)
txtSimple = ""
cd1.InitDir = "C:\Program Files\Apache Group\Apache2\logs"
cd1.Filter = "Log Files (*.log)|*.log"
cd1.ShowOpen
If cd1.FileName = "" Then
msg = MsgBox("No File Chosen.", vbInformation, "File Needed")
Exit Sub
End If
Open cd1.FileName For Input As #1
Do Until EOF(1)
Line Input #1, strNewLine
' get the ip string from the start of the log
strIP = (Mid(strNewLine, 1, 15))
'loop through the array to see if the ip is in it
For i = 1 To UBound(arrIPs)
' if it is, then go to the next line
If strIP = arrIPs(i) Then
GoTo skipwrite
' if not, then record it in the array
Else
'loop through array to find free spot for next ip
For j = 1 To UBound(arrIPs)
If arrIPs(j) = "" Then arrIPs(j) = strIP: GoTo PrintIP
Next j
End If
Next i
PrintIP:
txtSimple = txtSimple & strIP & strwrap
skipwrite:
Loop
Close #1
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|