CJ7
CJ7

Reputation: 23295

What is the effect of a semicolon at the end of a line?

What is the effect of having a semicolon at the end of a line of code?

I've seen this in some code I've taken over:

Printer.Print "Customer: " & strCustomerName & " (" & strCustomerCode & ")";

Upvotes: 3

Views: 5694

Answers (2)

Frankline
Frankline

Reputation: 41025

Print is a fundamental BASIC statement that dates back to the first days of the language in the mid-1960s. Print is used to display lines of data on a form, picture box, printer, and the immediate (Debug) window; it can also be used to write records of data to a file. In VB, Print is implemented as a method.

The general format for the Print method is:

[object.]Print [expressionlist]

where object refers to one of the objects mentioned above (Form, PictureBox, Debug window, Printer) and expressionlist refers to a list of one or more numeric or string expressions to print.

Items in the expression list may be separated with semicolons (;) or commas (,). A semicolon or comma in the expression list determines where the next output begins:

; (semicolon) means print immediately after the last value.
, (comma) means print at the start of the next "print zone".

Items in the expression list of a Print statement that are separated by semicolons print immediately after one another. In the statement

Print "Hello,"; strName; "How are you today?"

If strName contained "HARRY", the Print statement would generate the following output:

Hello,HARRYHow are you today?

Excerpt : Understanding semicolons and print method

Upvotes: 1

T.J. Crowder
T.J. Crowder

Reputation: 1075059

A ; at the end of a Print statement suppresses the usual default CRLF:

charpos - Specifies the insertion point for the next character. Use a semicolon to position the insertion point immediately after the last character displayed. Use Tab(n) to position the insertion point to an absolute column number. Use Tab with no argument to position the insertion point at the beginning of the next print zone. If charpos is omitted, the next character is printed on the next line.

(My emphasis)

I can't find a reference for Printer.Print (it's not listed if you click the "Methods" link here), but I expect it does the same thing.

Upvotes: 7

Related Questions