TABs and aligning columns

Basic and Machine Language

Moderator: Moderators

Post Reply
User avatar
pitcalco
just pitcalco
Posts: 1272
Joined: Wed Dec 28, 2005 4:13 pm
Location: Berlin

TABs and aligning columns

Post by pitcalco »

Having used things like Microsoft Word and other relatively recent word processing programs has perhaps spoiled me and has caused me to have too great expectations of the VIC and other 8-bit systems, however, I hope all the same that there is an elegant and not-too-difficult way to modify tabs on the VIC 20 using BASIC.

What I am thinking of is finding a way, for instance, of displaying columns of figures where the decimal point is aligned correctly relative to the figure above and below it. Say that I need to produce a column of prices, which are variable (i.e., I don't know how many digits each price will comprise) but I want them to line up correctly. Similarly, I would like to be able to right-justify tabs as well, just like one can do using Word.

Off hand, I would go about this in an incredibly awkward way using LEN, LEFT$, RIGHT$ etc. in a convoluted subroutine testing and comparing the length of each variable and making the necessary adjustments, but I hope someone else has a better way.

Granted that this would be of limited value on the VIC in 22-column mode, but I am thinking of 80-columns or even for use on the 80-column CBM. In the latter case, given that the CBM (PET) held itself out to be a business computer, I am a bit disappointed that this might not have been in mind when designing BASIC. (Then again, I am not so familiar with Basic 4.0).

A machine-language routine might be in order for this; however, I suspect that would require different routines for each system, i.e., VIC vs 64 vs CBM. For now, I would be interested in considering a more portable BASIC routine.
There are only three kinds of people in the world: those who can count and those who can't.

Paul Lambert
Berlin
Federal Republic of Germany
wimoos
Vic 20 Afficionado
Posts: 345
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: TABs and aligning columns

Post by wimoos »

In other (and contemporary) Basic dialects this would be done with the USING directive to the PRINT statement. The ExBasic/WimBasic extension to CBM Basic supports this. USING takes a string to format the (numeric) value that follows.

So for example

Code: Select all

PRINT USING "PRICE: ##.##", 4.5
PRINT USING "PRICE: ##.##", 13.2 
will then produce

Code: Select all

PRICE:  4.50
PRICE: 13.20
Two digits before the period and two digits after. This is just a simple example, more complex strings can be used as well.

Regards,

Wim.
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
User avatar
pitcalco
just pitcalco
Posts: 1272
Joined: Wed Dec 28, 2005 4:13 pm
Location: Berlin

Re: TABs and aligning columns

Post by pitcalco »

Thanks wimoos.

Indeed, PRINT USING is very useful in newer BASIC dialects. I guess I am looking for a way get the same effect on the VIC.
There are only three kinds of people in the world: those who can count and those who can't.

Paul Lambert
Berlin
Federal Republic of Germany
wimoos
Vic 20 Afficionado
Posts: 345
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Re: TABs and aligning columns

Post by wimoos »

Use the WimBasic extension. See http://wimbasic.webs.com
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
User avatar
pitcalco
just pitcalco
Posts: 1272
Joined: Wed Dec 28, 2005 4:13 pm
Location: Berlin

Re: TABs and aligning columns

Post by pitcalco »

Pretty neat!
There are only three kinds of people in the world: those who can count and those who can't.

Paul Lambert
Berlin
Federal Republic of Germany
User avatar
Kweepa
Vic 20 Scientist
Posts: 1314
Joined: Fri Jan 04, 2008 5:11 pm
Location: Austin, Texas
Occupation: Game maker

Re: TABs and aligning columns

Post by Kweepa »

Here's a "simple" solution from "Mastering the VIC-20":

Code: Select all

PRINT SPC(3)RIGHT$("    "+STR$(X%(I),6))
If you need to align the dot, you'd need to find it first unfortunately...
https://archive.org/details/Mastering_the_VIC-20 p13
Post Reply