📄 eventlog.frm
字号:
VERSION 5.00
Begin VB.Form frmEventLog
BorderStyle = 3 'Fixed Dialog
Caption = "事件日志跟踪"
ClientHeight = 2625
ClientLeft = 45
ClientTop = 330
ClientWidth = 9345
ControlBox = 0 'False
Icon = "EventLog.frx":0000
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2625
ScaleWidth = 9345
ShowInTaskbar = 0 'False
Begin VB.CommandButton cmdPrintLog
Caption = "打印日志"
Default = -1 'True
Height = 375
Left = 7920
TabIndex = 0
Top = 1560
Width = 1215
End
Begin VB.ListBox lstEventsTracked
Height = 780
Left = 240
Sorted = -1 'True
TabIndex = 3
TabStop = 0 'False
Top = 1560
Width = 7455
End
Begin VB.ListBox lstEventLog
Height = 780
Left = 240
TabIndex = 2
TabStop = 0 'False
Top = 360
Width = 8895
End
Begin VB.CommandButton cmdClearLog
Caption = "清除日志"
Height = 375
Left = 7920
TabIndex = 1
Top = 2040
Width = 1215
End
Begin VB.Label lblEventsTracked
Caption = "日志"
Height = 252
Left = 240
TabIndex = 5
Top = 1320
Width = 1332
End
Begin VB.Label lblEventLog
Caption = "日志 (最近在上面文本框; 历史事件在下面文本框)"
Height = 255
Left = 240
TabIndex = 4
Top = 120
Width = 6975
End
End
Attribute VB_Name = "frmEventLog"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
'**************************************************************
' Module (Private) Variables
'**************************************************************
'----------------------------------------------------------
' Event Log Variables
'----------------------------------------------------------
Private mstrLogFileFullPath As String
Private mstrLogFile As String
Private mintReturnCode As Integer
'**************************************************************
' Module (Private) Constants
'**************************************************************
'----------------------------------------------------------
' Constants used to control log behavior.
'----------------------------------------------------------
Private Const LOG_FILE_PREFIX = "IMGLOG" 'Logfile prefix.
Private Const EVENT_COUNT_LIMIT = 300 'Max number of events listed
'in the listbox.
Private Sub cmdClearLog_Click()
'**************************************************************
' PRIVATE SUB cmdClearLog_Click: Clear the EventLog listbox.
'**************************************************************
lstEventLog.Clear
End Sub
Private Sub cmdPrintLog_Click()
'**************************************************************
' PRIVATE SUB cmdPrintLog_Click: Print the Event Log.
'**************************************************************
'** Booleans
Dim blnError As Boolean
'** Integers
Dim intCounter As Integer
Dim intFileNumber As Integer
Dim intLineCounter As Integer
Dim intListBoxIndex As Integer
'** Strings
Dim strEvent As String
Dim strFileName As String
Dim strHeader As String
Dim strItemNo As String
Dim strLeft As String
Dim strRight As String
On Error Resume Next
'----------------------------------------------------------
' Set the mousepointer to an hourglass.
'----------------------------------------------------------
Screen.MousePointer = vbHourglass
'----------------------------------------------------------
' Look for previous IMGLOGn.TXT files, and based on that
' generate the new IMGLOGn.TXT filename.
'----------------------------------------------------------
strFileName = Dir$(gstrAppDirectory & "\" _
& LOG_FILE_PREFIX & "00.TXT")
If strFileName <> "" Then
intCounter = 0
Do Until strFileName = ""
intCounter = intCounter + 1
strFileName = Dir$(gstrAppDirectory & "\" _
& LOG_FILE_PREFIX & Format(intCounter, "00") & ".TXT")
Loop
mstrLogFile = UCase$(LOG_FILE_PREFIX & Format(intCounter, "00") & ".TXT")
mstrLogFileFullPath = gstrAppDirectory & "\" & mstrLogFile
Else
mstrLogFile = UCase$(LOG_FILE_PREFIX & "00.TXT")
mstrLogFileFullPath = gstrAppDirectory & "\" & mstrLogFile
End If
'----------------------------------------------------------
' Open the log file and print the initial header.
'----------------------------------------------------------
intFileNumber = FreeFile
Open mstrLogFileFullPath For Output As #intFileNumber 'Open the log file
Call PrintReportInitialHeader(intFileNumber, mstrLogFileFullPath) 'Print header information (program, date...)
'----------------------------------------------------------
' Note that events are printed in temporal order.
'----------------------------------------------------------
Print #intFileNumber, ""
Print #intFileNumber, gstrAsterisks
strLeft = "* Note: "
strRight = "Events are printed from first to last: old events are at the top; recent events are at the bottom."
Call PrintReportWrapLine(intFileNumber, strLeft, strRight, " ")
Print #intFileNumber, gstrAsterisks
Print #intFileNumber, ""
'----------------------------------------------------------
' Print the "Events Tracked" header, and initialize
' strItemNo and intLineCounter.
'----------------------------------------------------------
strHeader = "Events Tracked"
Call PrintReportHeader(intFileNumber, strHeader, gstrAsterisks, 0) 'Print the header
strItemNo = Space$(STRITEMNO_LENGTH)
intLineCounter = 0
'----------------------------------------------------------
' Print the events tracked in alphabetical order, since
' the listbox items are sorted.
'----------------------------------------------------------
If lstEventsTracked.ListCount = 0 Then
Print #intFileNumber, " Note: No events are being tracked."
Else
For intListBoxIndex = 0 To lstEventsTracked.ListCount - 1
intLineCounter = intLineCounter + 1
RSet strItemNo = intLineCounter & ". "
strEvent = lstEventsTracked.List(intListBoxIndex)
Call PrintReportWrapLine(intFileNumber, strItemNo, strEvent, " ")
Next intListBoxIndex
End If
'----------------------------------------------------------
' Print the "Events Logged" header, and initialize
' strItemNo and intLineCounter.
'----------------------------------------------------------
strHeader = "Events Logged"
Call PrintReportHeader(intFileNumber, strHeader, gstrAsterisks, 0) 'Print the header
strItemNo = Space$(STRITEMNO_LENGTH)
intLineCounter = 0
'----------------------------------------------------------
' Print the events logged. Note that events are taken from
' the listbox from the bottom up (Step -1). This prints
' them in the opposite order in which they are displayed.
' They are displayed on the form with recent events at the
' top; on the form this prevents having to scroll to see
' the most recent event. They are printed in the log with
' old events at the top; this is done because people are
' used to reading reports in chronological order.
'----------------------------------------------------------
If lstEventLog.ListCount = 0 Then
Print #intFileNumber, " Note: No events have been logged."
Else
For intListBoxIndex = lstEventLog.ListCount - 1 To 0 Step -1
intLineCounter = intLineCounter + 1
RSet strItemNo = intLineCounter & ". "
strEvent = lstEventLog.List(intListBoxIndex)
Call PrintReportWrapLine(intFileNumber, strItemNo, strEvent, " ")
Next intListBoxIndex
End If
'----------------------------------------------------------
' Close the output file and reset the mousepointer.
'----------------------------------------------------------
Close #intFileNumber 'Close the output file.
Screen.MousePointer = vbArrow 'Set the mouse pointer back to an arrow.
'----------------------------------------------------------
' Use NotePad to display the file. If the file is too
' large for NotePad to display, it will automatically come
' up and ask if you wish to use WordPad instead.
'----------------------------------------------------------
If blnError = False Then
MsgBox INFO_IN_FILE & mstrLogFileFullPath & ".", vbInformation
mintReturnCode = WinExec(gstrWindowsDirectory & "\NOTEPAD.EXE " & mstrLogFileFullPath, 1)
End If
End Sub
Private Sub Form_Load()
'**************************************************************
' PRIVATE SUB Form_Load: Load the form.
'**************************************************************
'----------------------------------------------------------
' If the form isn't minimized or maximized, display it on
' the lower portion of the screen.
'----------------------------------------------------------
If WindowState = 0 Then
Move (Screen.Width - frmEventLog.Width) / 2, _
(Screen.Height * 0.7)
End If
End Sub
Public Sub GenerateLogEvent(mstrPMEType As String, mstrEventName As String, mstrParameters As String)
'**************************************************************
' PUBLIC SUB GenerateLogEvent: Add an item to the EventLog
' listbox. If it has too many items, delete the oldest one.
'**************************************************************
lstEventLog.AddItem "[" & Format(Time, "hh:mm:ss") & "] " & mstrEventName & " (" & mstrParameters & ")", 0
If lstEventLog.ListCount > EVENT_COUNT_LIMIT Then
lstEventLog.RemoveItem (frmEventLog.lstEventLog.ListCount - 1)
End If
End Sub
Public Sub RemoveTrackedEvent(strItemDescription As String)
'**************************************************************
' PUBLIC SUB RemoveTrackedEvent: Remove an item from the
' EventsTracked listbox.
'**************************************************************
'** Integers
Dim intListBoxIndex As Integer
If frmEventLog.lstEventsTracked.ListCount > 0 Then
For intListBoxIndex = 0 To frmEventLog.lstEventsTracked.ListCount - 1
If strItemDescription = frmEventLog.lstEventsTracked.List(intListBoxIndex) Then
lstEventsTracked.RemoveItem (intListBoxIndex)
Exit For
End If
Next intListBoxIndex
End If
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -