-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLogger.cls
52 lines (44 loc) · 1.22 KB
/
Logger.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "Logger"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
' logger built with help from https://excelmacromastery.com/vba-error-handling/
Dim m_fileName As String
Dim m_fileNumber As Variant
Public Sub openFile(path As String)
' Archive at 20kb of data
If dir(path) <> "" Then
If FileLen(path) > 20000 Then
FileCopy path _
, Replace(path, ".txt", Format(Now, "ARCHIVED ddmmyyyy hhmmss.txt"))
Kill path
End If
End If
m_fileName = path
m_fileNumber = FreeFile
Open m_fileName For Append As m_fileNumber
End Sub
Public Sub writeToFile(sType As String, sSource As String, sDetails As String, Optional path As String)
Dim data As String
data = sType & ", " & sSource & ", " & sDetails
If Not path = "" Then
openFile (path)
printToFile (data)
closeFile
Else
printToFile (data)
End If
End Sub
Public Sub closeFile()
Close m_fileNumber
End Sub
Private Sub printToFile(data As String)
Debug.Print data
Print #m_fileNumber, data
End Sub