'===========================================================================
'Name: CallLogger.vbs
'Author David Wheater
'Date 30/08/2013
'Purpose Parses output from Meridian Call Logger
'---------------------------------------------------------------------------
'30/08/2013 Version 1.0 Initial Build
'===========================================================================
'Create Objects
Set objShell = CreateObject("Wscript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("Wscript.Network")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
'===========================================================================
' Variables
'===========================================================================
strLogFile = "details.txt"
strCallsPath = "Y:\" '<< Change to wherever your Call Log files are.
'===========================================================================
' Start of Script
'===========================================================================
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.add
objExcel.Visible = True
objExcel.Range("A1").Value = "Type"
objExcel.Columns("A").NumberFormat = "@"
objExcel.Range("A1").ColumnWidth = 4.57
objExcel.Range("B1").Value = "From"
objExcel.Columns("B").NumberFormat = "@"
objExcel.Range("B1").ColumnWidth = 9.3
objExcel.Range("C1").Value = "To"
objExcel.Columns("C").NumberFormat = "@"
objExcel.Range("C1").ColumnWidth = 9.3
objExcel.Range("D1").Value = "Dialled"
objExcel.Columns("D").NumberFormat = "@"
objExcel.Range("D1").ColumnWidth = 14
objExcel.Range("E1").Value = "Date"
objExcel.Range("e1").ColumnWidth = 11
objExcel.Range("F1").Value = "Time"
objExcel.Range("F1").ColumnWidth = 9
objExcel.Range("G1").Value = "Length"
objExcel.Range("G1").ColumnWidth = 9
objExcel.Range("H1").Value = "CLID"
objExcel.Columns("H").NumberFormat = "@"
objExcel.Range("H1").ColumnWidth = 14
objExcel.Range("I1").Value = "OrigTN"
objExcel.Columns("I").NumberFormat = "@"
objExcel.Range("J1").Value = "TermTN"
objExcel.Columns("J").NumberFormat = "@"
objExcel.Range("K1").Value = "TTA"
objExcel.Columns("K").NumberFormat = "@"
objExcel.Range("K1").ColumnWidth = 8
objExcel.Range("L1").Value = "ReDir"
objExcel.Columns("L").NumberFormat = "@"
objExcel.Range("M1").Value = "TWT"
objExcel.Columns("M").NumberFormat = "@"
objExcel.Range("N1").Value = "100 Hour"
intRow = 2
strRecType = ""
Set objFolder = objFSO.GetFolder (strCallsPath)
For Each objFile in objFolder.Files
'Wscript.Echo "Reading... " & objFile.path
ReadFile objFile.path
Next
Sub ReadFile(strCallsFile)
Set objCalls = objFSO.OpenTextFile(strCallsFile,ForReading)
Do Until objCalls.AtEndOfStream
strLine = objCalls.ReadLine
'Strip out Null characters
strLine = Replace(strLine,Chr(0),"")
strLine = Replace(strLine,Chr(0),"")
strLine = Replace(strLine,Chr(0),"")
strLine = Replace(strLine,Chr(0),"")
If Len(strLine) >= 88 Then
strRecType = Left(strLine,1)
strFrom = strip(mid(strLine,10,7))
strTo = strip(mid(strLine,18,7))
strDialled = Strip(Mid(strLine,52,22))
strDate = Strip(Mid(strLine,26,5)) & "/" & Year(now())
strtime = Strip(Mid(strLine,32,8))
strLength = Strip(Mid(strLine,41,8))
ElseIf Len(strLine) = 87 Then
strCLID = Strip(Mid(strLine,3,16))
strOrigTN = Strip(Mid(strLine,54,11))
strTermTN = Strip(Mid(strLine,66,11))
ElseIf Len(strLine) = 52 Then
strTTA = Strip(Mid(strLine,3,5))
strReDir = Strip(Mid(strLine,8,1))
strTWT = Strip(Mid(strLine,9,5))
str100 = Mid(strLine,40,3)
ElseIf Len(strLine) = 1 Then
If strRecType >= "A" and strRecType =< "Z" Then
objExcel.Cells(intRow,1).Select
objExcel.Cells(intRow,1).Value = strRecType
objExcel.Cells(intRow,2).Value = strFrom
objExcel.Cells(intRow,3).Value = strTo
objExcel.Cells(intRow,4).Value = strDialled
objExcel.Cells(intRow,5).Value = strDate
objExcel.Cells(intRow,5).NumberFormat = "dd/mm/yyyy"
objExcel.Cells(intRow,6).Value = strTime
objExcel.Cells(intRow,6).NumberFormat = "hh:mm:ss"
objExcel.Cells(intRow,7).Value = strLength
objExcel.Cells(intRow,6).NumberFormat = "hhh:mm:ss"
objExcel.Cells(intRow,8).Value = strCLID
objExcel.Cells(intRow,9).Value = strOrigTN
objExcel.Cells(intRow,10).Value = strTermTN
objExcel.Cells(intRow,11).Value = strTTA
objExcel.Cells(intRow,12).Value = strReDir
objExcel.Cells(intRow,13).Value = strTWT
objExcel.Cells(intRow,14).Value = str100
intRow = intRow +1
End If
strRecType = ""
strFrom = ""
strTo = ""
strDialled = ""
strDate = ""
strTime = ""
strLength = ""
strCLID = ""
strTTA = ""
Else
LogToFile Len(strLine)
End If
Loop
End Sub
'Finish off spreadsheet and show
objExcel.Range("A:N").Autofilter
objExcel.Range("A2").Select
objExcel.ActiveWindow.FreezePanes = True
objExcel.Visible = True
objShell.Popup "Done.", 10
'===========================================================================
' Support Subroutines
'===========================================================================
Sub LogToFile(strMsg)
If objFSO.FileExists(strLogFile) Then
Set objLogFile = objFSO.OpenTextFile(strLogFile,ForAppending)
Else
Set objLogFile = objFSO.CreateTextFile(strLogFile)
End If
objLogFile.WriteLine strMsg
'Wscript.Echo strMsg
objLogFile.Close
End Sub
Function Strip(strString)
tmp = Trim(strString)
tmp = Replace(tmp,Chr(0),"")
tmp = Replace(tmp,"X","")
tmp = Replace(tmp," ","")
tmp = Replace(tmp,"A","")
Strip = tmp
End Function