I have to code logging of program and i found similar code but still dont know how to code it. The code of Log file:
Option Explicit
Public Enum LogTypeEnum
ltInfo = 1
ltWarning = 2
ltError = 3
End Enum
Public Enum LogProgramDomainEnum
lpdRole = 1
lpdCinnosti = 2
End Enum
Private mWinAdLogCol As New EMWinAdLog.WinAdLogCol
Private mFrmLog As New EMWinAdLog.WinadLogFrm
Public Sub WinADLogInit(cfg As EMACTIVEXLib.EMCONFIG, ByVal ProgramID As Integer)
mWinAdLogCol.Init cfg, ProgramID
mFrmLog.AddLogType LogTypeEnum.ltInfo, "Info"
mFrmLog.AddLogType LogTypeEnum.ltWarning, "Warning"
mFrmLog.AddLogType LogTypeEnum.ltError, "Error"
mFrmLog.AddProgramDomain LogProgramDomainEnum.lpdRole, "Role"
mFrmLog.AddProgramDomain LogProgramDomainEnum.lpdCinnosti, "Activity"
mFrmLog.Init cfg, ProgramID
End Sub
Public Sub WriteLog(LogProgramDomain As LogProgramDomainEnum, LogType As
LogTypeEnum,Description1 As String, Optional Description2 As String = "")
mWinAdLogCol.xAdd LogProgramDomain, LogType, Description1, Description2
End Sub
Public Sub ShowLog()
mFrmLog.Show 0
End Sub
Public Sub Done()
mFrmLog.Done
Set mFrmLog = Nothing
Set mWinAdLogCol = Nothing
End Sub
and for exmaple i have an event:
Private Sub cmAdd_Click()
Load frmAddrolu
frmAddrolu.Show vbModal, Me
If frmAddrolu.Nazov <> "" Then
Dim LokRola As TRola
Set LokRola = Role.xAdd(frmAddrolu.Nazov)
ZobrazRoleToLst cmbRole, Role
SetCmbItem cmbRole, LokRola.RolaID
If cmbRole.ListIndex >= 0 Then
ZobrazSkupiny AllSkupiny, RolaProgramPristup, treeSkup, True
treeSkup_NodeClick treeSkup.SelectedItem
End If
End If
End Sub
I wrote only example because i have no idea how to do it. Thanks for example or explanation or any help from you.
MicSim is correct, it is not hard. My basic logging Sub is below feel free to take it and use it or change it to suit your particular needs. I use this in a .bas file in the application. There is also code in here that allows you to limit the file size.
The ShowDateTime, sAltFileName, and lMaxFileSize parameters are optional. To use this method you just call it from where ever you want to write a message to the log.
WriteDebugFile "The code just did something."
Or if you prefer using the Call statement,
Call WriteDebugFile("The code just did something.")