Code:
Imports System.IO Sub Main(ByVal Parms As String) Dim logName As String = "Log to File" 'set log type for HS log Dim Debug As Boolean = False 'set to True if the script give you errors and it will provide additional info in the HS3 log to help troubleshoot Try Dim ParmArray() As String = Split(Parms,"|") 'split parameter into an array Dim refID As Integer = CInt(ParmArray(0)) 'the first parameter is the reference id of the device Dim loggingFileName As String = ParmArray(1) 'the second parameter is the file name to log too Dim CurDate As String = Now.ToString("yyyy-MM-dd") Dim CurTime As String = Now.ToString("hh:mm:ss tt") Dim CurValue As String = CStr(hs.DeviceValueEx(refID)) Dim mydocpath As String = hs.GetAppPath & "/data/" & loggingFileName & ".csv" If Debug Then hs.writelog(logName,mydocpath) If Debug Then hs.writelog(logName,CurDate & "," & CurTime & "," & CurValue) Using outputFile As New StreamWriter(mydocpath, True) outputFile.WriteLine(CurDate & "," & CurTime & "," & CurValue) End Using Catch ex As Exception hs.WriteLog(logName, ex.Message) End Try End Sub
Leave a comment: