Announcement

Collapse

Contacting HomeSeer This Week

HomeSeer is open and operational this week. All orders are being processed and shipped as usual. However, some staff are working from home. If you need to contact HomeSeer for support or customer service, please use our Email or Chat options. https://homeseer.com/contact-us/
See more
See less

Need help sending CID to log file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need help sending CID to log file

    In my WAF NetCallerID script, I've added a section that writes the CID to a text file. I want the newest numbers to appear at the top of the file, so I've written it so that the new CID info gets saved to a temp file, then the contents of the the main CID log file are appended to the temp file and finally, the entire thing gets written back to the main log file. The code is as follows...
    Code:
    	Dim objFSO
    	Dim objFile
    	Set objFSO = CreateObject("Scripting.FileSystemObject")
    	sPath=hs.GetAppPath & "\data\WAF-NetCallerID\"
    
    	Set objFile= objFSO.OpenTextFile(sPath & "cid_temp.txt", 2, True)
    	objFile.WriteLine sName & " " & chr(124) & " " & s_ncid_number & " " & chr(124) & " " & s_ncid_date
    	objFile.Close
    
    	Set objFile= objFSO.OpenTextFile(sPath & "cid_log.txt", 1, False)
    	strLogFile = objFile.ReadAll
    	objFile.Close
    
    	Set objFile= objFSO.OpenTextFile(sPath & "cid_temp.txt", 8, True)
    	objFile.Write strLogFile
    	objFile.Close
    
    	If objFSO.FileExists(sPath & "cid_temp.txt") Then
    		objFSO.CopyFile sPath & "cid_temp.txt", sPath & "cid_log.txt"
    		objFSO.DeleteFile "cid_temp.txt"
    	End If
    Here's the problem... I'm only seeing the newest CID info in the main log file. The previous info seems to be there because the file size increases and there are selectable lines of blank "stuff" plus a few weird characters in the log. See the following...
    Any ideas? Am I doing something wrong? Is there a better way to sort the log file than what I'm doing?

    P.S. I do not have HSP.

  • #2
    Try this, it works great for me to get the last 10 callers into virtual devices to show in MainLobby.

    "sub main()
    arrLogData = GetLogData
    MaxLine = UBound(arrLogData)

    ' Move the pointer to the beginning of the day by reading the file backwards
    ' until I find yesterdays date.
    For i = MaxLine To 1 Step -1
    r = InStr(1, arrLogData(i), Date - 1)
    If r > 0 Then
    Exit For
    End If
    Next

    iCount = 10
    For LoopLine = MaxLine To i Step -1
    strLogTemp = arrLogData(LoopLine)
    strLogTemp = replace(strLogTemp,"~"," ")
    strLogTemp = replace(strLogTemp,"!"," ")
    If InStr(1, UCase(strLogTemp), UCase("Number")) Then
    if iCount <= 30 then
    hs.SetDevicestring "s" & iCount, strLogTemp, True
    iCount = iCount +1
    'MsgBox (strLogTemp)
    end if
    End If
    Next

    End Sub


    Function GetLogData()

    Const OpenFileForReading = 1
    Const OpenFileForWriting = 2
    Const OpenFileForAppending = 8

    Dim objFSO, objFile, objLog
    Dim strLog, strLogTemp
    Dim iCount
    Dim arrLog()

    strLog = "c:\program files\homeseer\WAF_Callers.log"
    strLogTemp = "c:\temp\WAF_Callers.tmp"

    'Create File System Object
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    If Not objFSO.FileExists(strLog) Then Exit Function

    'Get file handle
    Set objLog = objFSO.GetFile(strLog)

    objFSO.CopyFile strLog, strLogTemp
    'Open File For Reading
    Set objFile = objFSO.OpenTextFile(strLogTemp, OpenFileForReading)

    'Lets test object, then build our array if not at end of file
    If IsObject(objFile) Then
    Do Until objFile.AtEndOfStream
    ReDim Preserve arrLog(iCount)
    arrLog(iCount) = objFile.ReadLine
    iCount = iCount + 1
    Loop

    'Close the file so we can delete it :-)
    objFile.Close

    'Delete Temp Log File
    objFSO.DeleteFile (strLogTemp)
    End If

    GetLogData = arrLog

    'Clean Up
    Set objLog = Nothing
    Set objFile = Nothing

    End Function"

    Tim
    FB Page - https://www.facebook.com/pages/Capt-Tim/209398425902188

    HSTouch Layouts - https://www.facebook.com/media/set/?...5902188&type=3

    No, Im from Iowa. I only work in outer space. Captain Kirk

    Comment

    Working...
    X