Debug.Print Method |
object.Print [outputlist]
object
Use: Required
Data Type: Debug object
Always evaluates to the Debug object.
outputlist
Use: Optional
Data Type: String
Expression or list of expressions to print. If omitted, a blank line is printed (for details, see the following table).
{Spc(n) | Tab(n)} expression charpos
Spc( n)
Use: Optional
Inserts n space characters in the output string.
Tab( n)
Use: Optional
Inserts a Tab character at position n.
expression
Use: Optional
Numeric or string expression to print in the Immediate window.
charpos
Use: Optional
Determines the position of the next character.
Prints text in the Immediate pane of the Debug window in the design-time environment.
expression can include literal, numeric, string, and variant data.
If charpos is a semicolon (;), the next character immediately follows the last character of expression. For example:
Debug.Print sFileName; iFileNo
The Tab(n) argument doesn't actually insert any tab characters (Chr(9)); it fills the space from the end of the last expression to column n (or to the start of the next print zone) with space characters.
You can also use Tab(n) as the charpos argument to position the next character at an absolute column number.
If charpos is omitted, a carriage return is appended to expression, and the next character is printed on the next line.
Use the & concatenation character to create an output string from several elements.
The Debug.Print method uses the locale settings of the current system to format dates, times, and numbers using the correct separators.
#Const ccDebug = 1 ... #If ccDebug Then Debug.Print "Value of dblx: " & dblx #End if
The Debug.Print method examines the values of variables or traces program flow in a programming running within the VB or VBA design-time environment. It allows you to gather information about your program without interrupting its execution, as you would if you set breakpoints or used the MsgBox function to display debugging messages or the values of program variables.
Unlike the retail version of VB, the Debug object in the VBA development environment doesn't include an Assert method.
Certain data types may not behave as you'd expect, as this table shows:
Output Data Type | Formatted Output to Immediate Window |
---|---|
Boolean | True or False |
Date | Short Format Date as per system locale settings |
Error | Error followed by the corresponding error code |
Null (Variant) | Null |
In Visual Basic applications, Debug.Print executes only when an application is run in the design-time environment; the statement has no effect in a compiled application. Similarly, in Microsoft Office, Debug.Print executes only when the Visual Basic editor window is open and the Immediate window is displayed. This means that Debug.Print never produces a runtime error if the call to it is inappropriate, and that you don't have to remove Debug.Print from finished code or separate it with conditional #If...Then statements.