A quick one.

Anything Sinclair ZX Basic related; history, development, tips - differences between BASIC on the ZX80 and ZX81
Post Reply
Shaun_B
Posts: 451
Joined: Wed Apr 22, 2009 10:22 am

A quick one.

Post by Shaun_B » Mon Jun 09, 2014 12:39 am

Sorry if this has been done before, but here's a quick example of centered (centred) and right-justified text in BASIC (yeah, I know it's fairly small beer...)

Code: Select all

  1 PRINT "01234567890123456789012345678901"
  2 LET M$="DONKEYSOFT MMXIV"
  3 LET L=1
  4 GOSUB 100
  5 LET M$="RIGHT JUSTIFIED"
  6 LET L=0
  7 GOSUB 100
  8 STOP
100 LET T=32-LEN M$
101 IF L THEN LET T=T/2
102 PRINT TAB T;M$
103 RETURN
It's really quite simple: the variable M$ is used for the message that you want to output to the screen, and L is used as a boolean, if 1 or more then it's centered (centred) text and if 0 then it's right-justified. The logic in lines 100 - 103 should be fairly self-explanatory.

Regards,

Shaun.

Post Reply