Page 1 of 1

TABs and aligning columns

Posted: Fri Jan 16, 2015 7:04 am
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.

Re: TABs and aligning columns

Posted: Fri Jan 16, 2015 11:03 am
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.

Re: TABs and aligning columns

Posted: Fri Jan 16, 2015 5:51 pm
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.

Re: TABs and aligning columns

Posted: Sat Jan 17, 2015 3:57 am
by wimoos
Use the WimBasic extension. See http://wimbasic.webs.com

Re: TABs and aligning columns

Posted: Sat Jan 17, 2015 4:07 am
by pitcalco
Pretty neat!

Re: TABs and aligning columns

Posted: Mon Jan 19, 2015 6:48 pm
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