MSX BASIC – lesson 3

da | Nov 20, 2023 | MSX BASIC | 0 comments

“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

The correct syntax is PRINT USING “FORMAT STRING”; Topic1; Topic2; …..
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.
If we want to print only my name which is made up of 6 characters, we will use the backslash (\), 4 spaces and the backslash again. The more spaces we use, the more characters will be displayed.
The correct syntax is: PRINT USING “\ \”; N$
! : Prints only the first character of the sentence
PRINT USING “!”; N$ will only print the capital O of my name
& : Print the complete string phrase or variable. Example above: PRINT USING “&”;N$
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

Submit a Comment

Your email address will not be published. I campi obbligatori sono contrassegnati *

LEZIONE 26 – INTERVAL ON, RND ED ALTRI

LESSON 26 – INTERVAL ON, RND AND OTHERS

Good morning everyone, In this episode I will talk about an important interrupt, especially for games, when we want to make an enemy suddenly appear or a useful object, but also to create a stopwatch or a clock and many other things. The COMMAND exploits the...

LEZIONE 26 – INTERVAL ON, RND ED ALTRI

LESSON 24 – THE DATA MANAGED BY THE MSX (PART 3)

Kind regards to everyone. Today we will close this topic, I will talk about direct or random access files. But first, as I mentioned in the last episode, I will give a small explanation about the program. First of all, the first thing to say is that I used a command which...