“MSX BASIC” COLUMN by Orazio Cacciola (part 3)
PRINT USING
As mentioned last time, I will talk about PRINT USING or formatted printing. This function allows you to specify the print format using special characters.
They can be variables, constants or sentences
I will first specify special characters for alphanumeric phrases or variables;
\ \: Print the string variable for spaces that have been used.
Example: N$=”Orazio Cacciola”, my first and last name is 15 characters long including the space.
PRINT USING “!”; N$ will only print the capital O of my name
will print the complete sentence.
Special characters for variables or constants
# : Prints the number of positions before and after the decimal point Example: A=10.1: PRINT USING “##.##”; A. It will print 10,10, because we told it to print 2 numbers before the decimal point and 2 after it. If the number is larger than the format we used, it will still print it by putting the percent sign (%) in front. This only applies
for values above the decimal point, while those after are rounded.
+ or – : Placed at the beginning of the format string it will display the positive or negative sign of the variable.
– : Placed after the format string appears at the end of the variable
$ : Placed at the beginning it is displayed before the variable
** : Places many asterisks to the left of the variable for the entire length of the field.
**$ : As above plus adds the symbol $ before the variable
, : Putting before the decimal point ensures that it will be printed every 3 places of the decimal number. Example: A=1055.80: PRINT USING “####,.##”;A Will print 1,055.80
^^^^ = Placed at the end of the format string, the variable will be represented in the form of scientific notation
And finally you can combine sentences and numbers within the format string, just leave a space, both before and after.
Let's use the example from before by adding only the sentence.
PRINT USING ” Euro ####,.##”;A Will print 'Euro 1,055.80 or
PRINT USING “####,.## Euro”;A Will print 1,055.80 Euro
Small dilemma. I noticed that in some manuals instead of the $ (dollar) sign they use the £ (Lira) sign, but trying with the Philips, the first one is the correct one. Perhaps, at the time other manufacturers set the second as a special character.
If anyone is informed about this dilemma, write it in the comments, to clarify.
And that's it. Until next time
Orazio Cacciola



0 Comments