CPCWiki forum

General Category => Technical Support - Software related => Topic started by: Rabs on 10:03, 06 April 24

Title: Simple method to print leading zeros in BASIC?
Post by: Rabs on 10:03, 06 April 24
Is there are simple method to print leading zeros for a number in BASIC?

I would like to print a simple timer in minutes and seconds.

I have setup a simple timer calling a sub-routine every second, where I attempted to use PRINT USING to format the output but I guess it does not work as I expected.

80 window #3,36,40,1,1:paper #3,0:pen #2,1:cls #3:every 50,2 gosub 190:'Time After

180 'Time After
190 secs%=secs%+1
200 if secs%=60 then secs%=0:mins%=mins%+1
210 cls #3:locate #3,1,1:print #3 using "##";mins%;:print #3,":";:print #3, using "##";secs%;
220 return

You can see the resultant timer at the top right of the screen shot below and no leading zeros.

Print Using.JPG

So not quite what I wanted. Is there a simple way of printing leading zeros?
Title: Re: Simple method to print leading zeros in BASIC?
Post by: Jean-Marie on 11:43, 06 April 24
1 DEFINT a-z
10 secs=100:mins=100
80 WINDOW #3,36,40,1,1:PAPER #3,0:PEN #2,1:CLS #3:EVERY 50,2 GOSUB 190:'Time After
90 GOTO 90
180 'Time After
190 secs=secs+1
200 IF secs=160 THEN secs=100:mins=mins+1
210 CLS #3:LOCATE #3,1,1:PRINT #3,RIGHT$(STR$(mins),2);:PRINT #3,":";:PRINT #3,RIGHT$(STR$(secs),2);
220 RETURN
Title: Re: Simple method to print leading zeros in BASIC?
Post by: Rabs on 12:36, 06 April 24
Nice, Thank you.  :)
Title: Re: Simple method to print leading zeros in BASIC?
Post by: Rabs on 12:46, 06 April 24
Looks good. Thanks

Leading Zeros.JPG
Title: Re: Simple method to print leading zeros in BASIC?
Post by: SerErris on 12:04, 08 April 24
I am wondering what this applications is about ... looks great. Graphical debugger with showing all the CTRL lines states?

Title: Re: Simple method to print leading zeros in BASIC?
Post by: Rabs on 17:27, 08 April 24
Nothing that fancy I am afraid.

I am planning an Amstrad CPC evening at my Local Men's Shed.

They have quite a few members with electronic backgrounds (one person built his own NASCOM 3 back in 1980 :o ), so I plan on giving a talk about the design of the Amstrad CPC. But I want it to be interactive and get them using the CPCs.

I am taking along a 464, 664 and 6128 and with the original monitors (green and colour).  I will also take along some CPCs with open cases so they can inspect the PCB and components. I even plan on putting the program on tape and disk so they can load it.  :) hopefully.

The program is just a simple interactive guide that they can run through which tells them about the components (i.e. Z80, MUX, CRTC, Gate Array etc) and what they do in the CPC. I have written the program in basic so they can inspect it and have a play afterwards, I may even put Maxam on a ROM so they can do a bit of assembly from BASIC. 

Trick is trying to get the right level of information in the program so that everyone, both the electronic engineers and people with no background can work through it and get something from it.

Main aim is to drive discussion and interest.
Title: Re: Simple method to print leading zeros in BASIC?
Post by: ZorrO on 18:49, 08 April 24
Any chance for filming this?
What is MUX?
Title: Re: Simple method to print leading zeros in BASIC?
Post by: Rabs on 18:54, 08 April 24
Ah sorry by MUX, I mean the multiplexers, the 74LS153s. Not sure I can film the event I am afraid, if that is what you mean.
Title: Re: Simple method to print leading zeros in BASIC?
Post by: Urusergi on 21:02, 08 April 24
A bit optimized (no flicker):

1 DEFINT a-z:secs=100:mins=100
2 WINDOW#3,36,40,1,1:PAPER#3,0:PEN#2,1:CLS#3:EVERY 50,2 GOSUB 5:'Time After
3 GOTO 3
4 'Time After
5 secs=secs+1
6 IF secs=160 THEN secs=100:mins=mins+1
7 LOCATE#3,1,1:PRINT#3,RIGHT$(STR$(mins),2)+":"+RIGHT$(STR$(secs),2);:RETURN

EDIT:
Another method :

1 DEFINT a-z:secs=0:mins=0
2 WINDOW#3,36,40,1,1:PAPER#3,0:PEN#2,1:CLS#3:EVERY 50,2 GOSUB 5:'Time After
3 GOTO 3
4 'Time After
5 secs=secs+1
6 IF secs=60 THEN secs=0:mins=mins+1
7 LOCATE#3,1,1:PRINT#3,HEX$(6*(mins\10)+mins,2)+":"+HEX$(6*(secs\10)+secs,2);:RETURN
Powered by SMFPacks Menu Editor Mod