Reading Apache Logs?

imanta
05-02-2003, 04:46 PM
Has anyone ever tried parsing Apache logs line by line? I am using the standard Open and Read Line by Line, but this does not seem to work as the line delimiter is not a vbCrLf. I could be wrong but when I call Line Input #1, I get all the data at once.

Open FileName For Input As #1
Do While Not EOF(1)
Line Input #1, strData
Debug.Print strData
DoEvents
Loop
Close #1

Anyone ever do this? Any sample code??

Thanks!

Banjo
05-02-2003, 04:55 PM
I assume that its using vbLf as the line delimiter?
If so, then this should do the job:
Dim sLines() As String, iLine As Long
Dim f As Long, sFileData As String

' Read all file data into a string variable
f = FreeFile
Open filename For Input As #f
sFileData = Input$(LOF(f), f)
Close #f

' split the file into an array of lines
sLines = Split(sFileData, vbLf)
' loop through the line array and print each one
For iLine = LBound(sLines) To UBound(sLines)
Debug.Print sLines(iLine)
Next iLine

imanta
05-02-2003, 05:02 PM
Is there any way to know what a given text file is using as its Line Delimiter?? I have tried figuring this out before to no avail.

Thanks for the quick response!

Banjo
05-02-2003, 05:05 PM
No there isn't. VB simply assumes CRLF because that is what windows uses and VB is a windows only language.

imanta
05-02-2003, 05:12 PM
This code was the perfect help. Thanks again for your quick response!

Squirm
05-02-2003, 06:05 PM
What I do is strip out the vbCrs (using Replace$()) and use Split() with vbLf as delimiter.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum