Simple method to print leading zeros in BASIC?

Started by Rabs, 10:03, 06 April 24

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


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.

You cannot view this attachment.

So not quite what I wanted. Is there a simple way of printing leading zeros?


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);



Looks good. Thanks

You cannot view this attachment.


I am wondering what this applications is about ... looks great. Graphical debugger with showing all the CTRL lines states?

Proud owner of 2 Schneider CPC 464, 1 Schneider CPC 6128, GT65 and lots of books
Still learning all the details on how things work.


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.


Any chance for filming this?
What is MUX?
CPC+PSX 4ever


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.


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

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