| ページ一覧 | ブログ | twitter |  書式 | 書式(表) |

MyMemoWiki

Excel VBA Log Utility

提供: MyMemoWiki
2020年2月15日 (土) 07:32時点におけるPiroto (トーク | 投稿記録)による版 (ページの作成:「==Excel VBA Log Utility== [Excel VBA]{{category VBAソース片}} [Excel VBA File Utility] [FileUtil.cls]を使用 *Excel VBA File Utility ==='''Log.bas'''=== Opt…」)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
ナビゲーションに移動 検索に移動

Excel VBA Log Utility

[Excel VBA]テンプレート:Category VBAソース片

[Excel VBA File Utility] [FileUtil.cls]を使用

  • Excel VBA File Utility

Log.bas

Option Explicit

'
Private log         As FileUtil
Private m_IsOpen    As Boolean
'
' ログの初期化
'
' @param fileName 出力先ファイル
'
Public Sub initialLog(fileName As String)
    
    m_IsOpen = False
    Set log = New FileUtil
    
    m_IsOpen = log.openFile(fileName, FileMode.AppendMode)

End Sub
'
' ログの解放
'
Public Sub terminateLog()

    Call log.closeFile
    m_IsOpen = False
    Set log = Nothing

End Sub

'
' [INFO] ログの出力
'
' @param str メッセージ
'
Public Sub info(str As String)

    If Not isWritable() Then
        Exit Sub
    End If

    Call log.println(getTimeStamp & "[INFO] " & str)

End Sub
'
' [ERROR] ログの出力
'
' @param str メッセージ
'
Public Sub error(str As String)
    If Not isWritable() Then
        Exit Sub
    End If

    Call log.println(getTimeStamp & "[ERROR] " & str)
End Sub
'
' ログが書き込み可能か否か
'
' @param str メッセージ
'
Private Function isWritable() As Boolean
    
    isWritable = (m_IsOpen And log.isOpen)

End Function
'
' タイムスタンプ文字列生成
'
' @return タイムスタンプ文字列生成 "YYYY/MM/DD HH:MM:SS"
'
Private Function getTimeStamp() As String

    getTimeStamp = Date & " " & Time

End Function

テンプレート:Ref Log.bas