代码改变世界

写了个统一 OutputDebugString 输出的函数

2007-05-07 20:59  电脑人生  阅读(201)  评论(0编辑  收藏  举报

在程序中使用 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