【发布时间】:2013-12-23 18:43:36
【问题描述】:
为了在 VBA 中进行调试,我的代码中有几个 Debug.Print 语句。对于行解析块,我想打印该行,并在该行中输出任何 inline 标志,而在许多 if/elseif/else 块中没有多个 Debug.Print sFlag & sLine 语句。
有没有办法在 VBA 中抑制 Debug.Print 语句末尾的换行符?
【问题讨论】:
为了在 VBA 中进行调试,我的代码中有几个 Debug.Print 语句。对于行解析块,我想打印该行,并在该行中输出任何 inline 标志,而在许多 if/elseif/else 块中没有多个 Debug.Print sFlag & sLine 语句。
有没有办法在 VBA 中抑制 Debug.Print 语句末尾的换行符?
【问题讨论】:
事实证明,您只需在 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 上面的行。结果相同。