在程序中使用 OutputDebugString,既分散,也不便于调试与屏蔽,改了个过程 VB6OutputDebug:
Private Declare Sub OutputDebugString Lib "kernel32" Alias "OutputDebugStringA" (ByVal lpOutputString As String)
#Const VB6_OUTPUT_DEBUG = 1 '输出开关
Public Sub VB6OutputDebug(ByVal IsSplitOutput As Boolean, ByVal IsOutputCrLf As Boolean, ParamArray strLogMessage())
#If VB6_OUTPUT_DEBUG Then
If UBound(strLogMessage) = -1 Then Exit Sub
Dim i As Long
Dim strBuf As String
If IsSplitOutput = False Then
For i = 0 To UBound(strLogMessage)
strBuf = strBuf & strLogMessage(i) & " "
Next
OutputDebugString strBuf
Else
For i = 0 To UBound(strLogMessage)
OutputDebugString strLogMessage(i)
Next
End If
If IsOutputCrLf Then
Call OutputDebugString(vbCrLf)
End If
#End If
End Sub
演示:
Private Sub Command1_Click()
VB6OutputDebug False, False, "1", "2", "3"
VB6OutputDebug True, False, "a", "b", "c"
End Sub