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

MyMemoWiki

「Excel VBA Log Utility」の版間の差分

提供: MyMemoWiki
ナビゲーションに移動 検索に移動
(ページの作成:「==Excel VBA Log Utility== [Excel VBA]{{category VBAソース片}} [Excel VBA File Utility] [FileUtil.cls]を使用 *Excel VBA File Utility ==='''Log.bas'''=== Opt…」)
 
 
(同じ利用者による、間の3版が非表示)
1行目: 1行目:
==Excel VBA Log Utility==
+
==[[Excel VBA Log Utility]]==
[Excel VBA]{{category VBAソース片}}
+
[[Excel VBA]] | [[Category:VBAソース片]]
  
[Excel VBA File Utility] [FileUtil.cls]を使用
+
[[Excel VBA File Utility|FileUtil.cls]]を使用
*Excel VBA File Utility
+
*[[Excel VBA File Utility]]
 
==='''Log.bas'''===
 
==='''Log.bas'''===
 
  Option Explicit
 
  Option Explicit
71行目: 71行目:
 
  End Function
 
  End Function
 
  '
 
  '
  ' タイムスタンプ文字列生成
+
  ' [[タイムスタンプ]]文字列生成
 
  '
 
  '
  ' @return タイムスタンプ文字列生成 "YYYY/MM/DD HH:MM:SS"
+
  ' @return [[タイムスタンプ]]文字列生成 "YYYY/MM/DD HH:MM:SS"
 
  '
 
  '
  Private Function getTimeStamp() As String
+
  Private Function get[[TimeStamp]]() As String
 
   
 
   
     getTimeStamp = Date & " " & Time
+
     get[[TimeStamp]] = Date & " " & Time
 
   
 
   
 
  End Function
 
  End Function
  
 
{{ref Log.bas}}
 
{{ref Log.bas}}

2020年2月16日 (日) 04:25時点における最新版

Excel VBA Log Utility

Excel VBA |

FileUtil.clsを使用

Log.bas

  1. Option Explicit
  2.  
  3. '
  4. Private log As FileUtil
  5. Private m_IsOpen As Boolean
  6. '
  7. ' ログの初期化
  8. '
  9. ' @param fileName 出力先ファイル
  10. '
  11. Public Sub initialLog(fileName As String)
  12. m_IsOpen = False
  13. Set log = New FileUtil
  14. m_IsOpen = log.openFile(fileName, FileMode.AppendMode)
  15.  
  16. End Sub
  17. '
  18. ' ログの解放
  19. '
  20. Public Sub terminateLog()
  21.  
  22. Call log.closeFile
  23. m_IsOpen = False
  24. Set log = Nothing
  25.  
  26. End Sub
  27.  
  28. '
  29. ' [INFO] ログの出力
  30. '
  31. ' @param str メッセージ
  32. '
  33. Public Sub info(str As String)
  34.  
  35. If Not isWritable() Then
  36. Exit Sub
  37. End If
  38.  
  39. Call log.println(getTimeStamp & "[INFO] " & str)
  40.  
  41. End Sub
  42. '
  43. ' [ERROR] ログの出力
  44. '
  45. ' @param str メッセージ
  46. '
  47. Public Sub error(str As String)
  48. If Not isWritable() Then
  49. Exit Sub
  50. End If
  51.  
  52. Call log.println(getTimeStamp & "[ERROR] " & str)
  53. End Sub
  54. '
  55. ' ログが書き込み可能か否か
  56. '
  57. ' @param str メッセージ
  58. '
  59. Private Function isWritable() As Boolean
  60. isWritable = (m_IsOpen And log.isOpen)
  61.  
  62. End Function
  63. '
  64. ' タイムスタンプ文字列生成
  65. '
  66. ' @return タイムスタンプ文字列生成 "YYYY/MM/DD HH:MM:SS"
  67. '
  68. Private Function getTimeStamp() As String
  69.  
  70. getTimeStamp = Date & " " & Time
  71.  
  72. End Function

テンプレート:Ref Log.bas