VBA: Debug.Print without newline?
Asked Answered
C

1

13

For debugging in VBA, I have several Debug.Print statements throughout my code. For a line-parsing block, I'd like to print the line, and output any flags inline with the line, without having multiple Debug.Print sFlag & sLine statements throughout the many if/elseif/else blocks.

Is there a way, within VBA, to suppress the newline at the end of a Debug.Print statement?

Connecticut answered 23/12, 2013 at 18:43 Comment(0)
C
26

It turns out you can easily do this by simply adding a semicolon to the end of your Debug.Print statement. Like so:

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

So, some sample output will be:

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!
Connecticut answered 23/12, 2013 at 18:43 Comment(1)
Quite right. You could also put Debug.Print at very bottom, under Wend. Then close the line above Wend with a semi-colon. Same result.Lyublin

© 2022 - 2024 — McMap. All rights reserved.