Table of Contents

5.4.5.8 Print Statement

Note

This section describes the implementation of MS-VBAL §5.4.5.8 Print Statement.

Syntax

Form AST node Instruction kind(s) Notes
Print # PrintStatementNode Simple The file-number form. Token: Print.
Print PrintStatementNode Simple The bare form, with no file number (FileNumber is null): Print "x". See below.
Owner.Print ObjectPrintExpressionNode — The object-qualified form.
Debug.Print DebugPrintStatementNode Simple The object-qualified form whose owner is Debug.

Debug is written only as this statement and Debug.Assert: any other use of the name is a syntax error, as it is in MS-VBA (see RD-VBAL §5.4.2.23 Assert Statement).

An output list is a list of expressions, so in Debug.Print x = 0 and Owner.Print x = 0 the output list is the comparison x = 0: neither is a Let statement, whose target is never the Print of an object with an output list (RD-VBAL §5.4.3.8 Let Statement).

The output list these nodes carry is described in 5.4.5.8.1 Output Lists below. See RD-VBAL §3.4.3 File Statements.

The bare Print

Whether there is a bare Print at all is the language's to say (SupportedLanguage.HasBarePrint):

Language A Print with no file number
RD-VBA Not a statement. Print is a reserved identifier of VBA, illegal as a name and with no semantics, and it is no recognized statement inside a procedure. (Only the Immediate window accepts it, as Debug.Print; that is not procedure scope.) It is VBC09331, the same as any other name the language does not declare.
VB6 Undefined, for now: it is the Print member of the form or report it is written in, and the platform has no forms yet.
BASIC A statement. It writes to the session's own output - the one Debug.Print writes to - by the same output rules (5.4.5.8.1).

In BASIC it differs from Debug.Print in one way: it is not a debug statement, and is lowered in a release build, where Debug.Print leaves no instruction at all (RD-VBAL §3.5.1 InstructionList). It is what an interactive shell - which is written in BASIC - writes its output with: the shell's ? shorthand expands to it.

Instruction-list lowering is told the language the body is written in (InstructionLoweringOptions.Language, from the environment's IRuntimeEnvironmentProfile.Language) and reports the undefined form; a body lowered for no language is lowered as written.

Note

Not implemented. StatementStaticSemanticsEvaluator does not report it, having no language to ask: the language server has no live caller of it yet. A document module (a form, a report) with a Print member of its own is not yet the target of a bare Print written in it.

The ? shorthand has no lexer or grammar token: the shell expands it before the line is parsed.

Static Semantics

Note

Reserved. This section has no content yet.

Runtime Semantics

A number or a date in an output list is let-coerced to String, as MS-VBAL §5.4.5.8.1 says, in the regional settings of the session's environment (RD-VBAL §5.5.1.2.4 Let-coercion to and from String). Every form of Print is a text channel: a String is written as its whole characters, and a trailing byte is not written (RD-VBAL §2.4.1.2 VBStringType).

An object is printed as what it stands for, its default member's value, as the value it is (7 for an Excel range that holds 7). As in MS-VBA (recorded in Excel), for Print # and Debug.Print alike, Nothing is error 91 and an object whose default member takes an argument (a Collection) error 450.

Implementation

Print # writes through the channel's character output surface, IFileChannelOutput, which it shares with Write #. Width # sets that surface's maximum line length (RD-VBAL §5.4.5 File Statements).

5.4.5.8.1 Output Lists

Note

This section describes the implementation of MS-VBAL §5.4.5.8.1 Output Lists.

PrintStatementNode and ObjectPrintExpressionNode share one output-list shape:

Node Represents
PrintOutputItemNode An output item: a value and/or a ; or , separator.
PrintSpcClauseNode A Spc clause.
PrintTabClauseNode A Tab clause.
Tip

In a parsed output list, a value and its trailing separator are always two separate, alternating PrintOutputItemNodes: one value-only, one separator-only. MS-VBAL's outputItem grammar rule admits combining a value and its separator into one output item, but the generated parser never takes that alternative. A consumer of Items should walk the alternating list rather than assume (value, separator) pairs.

See RD-VBAL §3.4.3 File Statements.


⏮️ RD-VBAL §5.4.5.7 Width Statement | ⏭️ RD-VBAL §5.4.5.9 Write Statement