【问题标题】:VBA: Debug.Print without newline?VBA:Debug.Print 没有换行符?
【发布时间】:2013-12-23 18:43:36
【问题描述】:

为了在 VBA 中进行调试,我的代码中有几个 Debug.Print 语句。对于行解析块,我想打印该行,并在该行中输出任何 inline 标志,而在许多 if/elseif/else 块中没有多个 Debug.Print sFlag & sLine 语句。

有没有办法在 VBA 中抑制 Debug.Print 语句末尾的换行符?

【问题讨论】:

    标签: vba debugging newline


    【解决方案1】:

    事实证明,您只需在 Debug.Print 语句的末尾添加一个分号即可轻松做到这一点。像这样:

    While oExec.StdOut.AtEndOfStream = False
       sLine = oExec.StdOut.ReadLine
       If bInFileSystem Then
          If AnalyzeFileSystemLine(sLine) = False Then
             Debug.Print "[FSERR]: ";
          End If
       ElseIf bInWASCheck Then
          If AnalyzeWASLine(sLine) = False Then
             Debug.Print "[WASERR]: ";
          End If
       End If
    
       Debug.Print sLine
    Wend
    

    因此,一些示例输出将是:

    test text things look good!
    [FSERR]: uh oh this file system is at 90% capacity!
    some more good looking text :)
    [WASERR]: oh no an app server is down!
    

    【讨论】:

    • 完全正确。您也可以将Debug.Print 放在最底部,在Wend 下方。然后用分号关闭Wend 上面的行。结果相同。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-18
    • 2011-06-14
    • 2011-09-22
    • 1970-01-01
    • 2011-12-03
    相关资源
    最近更新 更多