Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA: Debug.Print without newline?

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?

like image 852
armstrhb Avatar asked Dec 23 '13 18:12

armstrhb


People also ask

What is vbNewLine in VBA?

vbNewLine inserts a newline character that enters a new line. In the below line of code, you have two strings combined by using it. Range("A1") = "Line1" & vbNewLine & "Line2" When you run this macro, it returns the string in two lines. It returns the character 13 and 10 (Chr(13) + Chr(10)).

How do you break a line in Excel VBA?

To break a single statement into multiple linesUse the line-continuation character, which is an underscore ( _ ), at the point at which you want the line to break.


1 Answers

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!
like image 67
armstrhb Avatar answered Dec 09 '22 10:12

armstrhb