Author |
Topic: Bug - or unrecognised feature? (Read 233 times) |
|
KenDown
New Member
member is offline


Posts: 49
|
 |
Re: Bug - or unrecognised feature?
« Reply #9 on: Dec 23rd, 2017, 02:21am » |
|
Curioser and curioser. A friend with whom I have been corresponding over this matter sent me the following program.
f$= "FONT Arial,32,B" a$="Kendall Down" b$="Kendall "+CHR$18+CHR$0+CHR$9+"Down" OSCLI(f$) VDU5 MOVE100,400:PRINTa$, WIDTH(a$)/2, @vdu%!220 MOVE100,300:PRINTb$, WIDTH(b$)/2, @vdu%!220
MOVE100,200:PRINTb$, WIDTH(b$)/2, @vdu%!220 MOVE100,100:PRINTa$, WIDTH(a$)/2, @vdu%!220 VDU4 END
When you run it the numbers in the top and bottom lines are further to the right than the numbers in the middle two lines. Now reverse the order of the lines, so that the two lines with b$ are at top and bottom and the two lines with a$ are in the middle. Run it again and it is *still* the top and bottom lines which have the numbers offset to the right!
I blame the litte green men on Mars, myself.
|
|
Logged
|
|
|
|
Richard Russell
Administrator
member is offline


Posts: 803
|
 |
Re: Bug - or unrecognised feature?
« Reply #10 on: Dec 23rd, 2017, 10:09am » |
|
on Dec 23rd, 2017, 02:21am, KenDown wrote:| When you run it the numbers in the top and bottom lines are further to the right than the numbers in the middle two lines. |
|
There's nothing strange going on here. What you are forgetting is that there are features of the PRINT statement which work properly only when all the characters output have the same width; specifically they are right-justified printing of numbers (which is the default) and tabulation using the TAB(n) function or the comma delimiter. The program you listed uses both right-justified numbers and the comma delimiter, so it is not surprising that it misbehaves.
PRINT simply counts the characters (bytes) you output - you can get the current value from the COUNT function - and assumes they all occupy the same width on the screen. When it tries to align the text to a specific column it outputs a number of spaces based on the current value of COUNT. If you select a proportional-spaced font, or use UTF-8 encoding, or incorporate 'non-printing' characters in strings, this doesn't work.
In that case you must take responsibility for formatting yourself, so if you want to have numbers printed right-justified, or tabulate output in columns, you cannot rely on the built-in features of the PRINT statement. Instead you will need to convert the numbers to strings (STR$), measure their width (WIDTH) and MOVE the graphics pointer to the appropriate place to achieve the required alignment.
Richard.
|
|
|
|
|