Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public globalFileHandle As Long
- Public globalFilePointer As Long
- Public Const LogFilePath = "\somewhere\"
- Public Const LogFileLimit = 65536
- Sub StartUpCode()
- Dim myHandle As Long, myPID As Long
- Dim FileName As String
- Dim myProgramName As String
- myHandle = GetMyHandle() ' function dependant on OS & API
- myPID = GetMyPID(myHandle) ' function dependant on OS & API
- myProgramName = GetMyProgramName(myHandle) ' function dependant on OS & API
- globalFileHandle = FreeFile
- globalFilePointer = 1 ' dependent on filesystem, either 1 or 0
- ' Note on filename
- ' This format is setup for generating a unique filename per instance
- ' Might not be desirable, will create a lot of log files
- FileName = LogFilePath _
- & Format$(Date, "yy-mm-dd") & "_" & Format$(Time, "hhmmss") _
- & myProgramName _
- & "_" & Format$(myPID) & "_" & Format$(myHandle) _
- & ".txt"
- Open FileName For Binary As globalFileHandle
- ' main code
- Close globalFileHandle
- End Sub
- Sub LogFileMessage(strMessage As String)
- Dim Work As String, msgLength As Long
- Work = Format$(Date, "yymmdd") & "_" & Format$(Time, "hhmmss") _
- & strMessage & vbCr
- msgLength = Len(Work & "--- ^ most recent ^ ---" & String$(5, vbCr))
- If ((msgLength + globalFilePointer) > LogFileLimit) Then
- globalFilePointer = 1 ' dependent on filesystem, either 1 or 0
- End If
- Seek globalFileHandle, globalFilePointer
- Put #fileout, , Work
- globalFilePointer = Seek(globalFileHandle)
- Put #fileout, , "--- ^ most recent ^ ---" & String$(5, vbCr)
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment