Hey guys, noob here.. I'm learning to work with arrays but I have a problem with my code somewhere...
My goal is to:
- load a text file
- grab the first 15 characters of each line and store to strIP each time
- see if the new value of strIP matches a value already in the array (arrIPs)
- if it doesn't, then add it..
- if it does, then add 1 to the count for this instance
That last one is my problem. I keep getting inaccurate numbers.
I.E. when something shows up in the text file about 34 times.. it is only showing a count of 2 or 1. I'm not sure what i've done wrong. Could ne1 help?
Everything works according to plan except for the counting.
As you can see, once the file is done loading, I display the count in another text box.... an inaccurate count.. grrrr
VB Code:
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, txtCharsToCopy)) 'loop through the array to see if the ip is in it Found = False For i = 0 To numIPs If strIP = arrIPs(i) Then Found = True arrIPcount(i) = (arrIPcount(i) + 1) Exit For End If Next i If Found = False Then arrIPs(numIPs) = strIP numIPs = numIPs + 1 ReDim Preserve arrIPs(numIPs) ReDim Preserve arrIPcount(numIPs) txtSimple = txtSimple & strIP & vbCrLf End If '======================== Loop Close #1 For i = 1 To UBound(arrIPcount) 'compensate for 0 starting count txtIPCount = txtIPCount & arrIPcount(i) & vbCrLf Next i




Reply With Quote