Tuesday, March 4, 2008

"Advanced" usage of the Print statement

I discovered this a couple of months ago, by coincidence (I actually read the documentation, instead of jumping to the example).

Punctuation characterPrint statement behavior
Semicolon or space in exprListThe next data item is printed with no spaces between it and the previous data item.
Semicolon at end of exprListThe next Print statement continues printing on the same line, with no spaces or carriage returns inserted.
Comma in exprListThe next data item is printed beginning at the next tab stop. (Tab stops are at every 14 characters.)
Comma at end of exprListThe next Print statement continues printing on the same line, beginning at the next tab stop. (Tab stops are at every 14 characters.)


In most of my previous code, when debugging, I wrote something like this:
Print "Field contents: " + doc.stringField(0) + ", " & doc.numberField(0)

Using the comma separated syntax, you can get away with:
Print "Field contents:", doc.stringField(0), doc.stringField(0)

I've started using the comma-separated syntax, when debugging, simply because it's less verbose/faster to write.

I did a little test to see how the different "methods" of using Print worked. It seems like the semicolon/comma a the end of the line doesn't work (see picture below). Either that, or I've misunderstood the documentation.

6 comments:

Julian Robichaux said...

I think the semi-colon at the end is for when you're printing to a file, not the status bar.

Tommy Valand said...

That may very well be..

I'll see if I can do a test tomorrow.

Charles Robinson said...

This goes way back to the original BASIC. :-) You could format text on the screen by using Print with commas and semicolons. You'd Print stuff in a loop with a comma after it to get columns of data, or print with a semicolon to make it run together.

And I'm not all that old, so don't even go there! I just started young. :-)

Jake Howlett said...

What about on the web? What happens there when you print with this syntax?

Tommy Valand said...

Same as with printing to the status bar (formatting is only visible in source).

Tommy Valand said...

@Julian: I tested printing to a file, using the Print #fileNum,-syntax, and it worked correctly.

I think that means that the documentation is wrong.

Print #.. (Prints data to a sequential text file) only have the semicolon/comma in expression list in the documentation.

Print (Prints data to the screen) has semicolon/comma both at the end of the line/in expression list documented.