Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print Using?
#1
For a clock timer, I'm just wondering if there's a way to make the leading 0 appear when the time is 1:05 etc  (I'm getting 1: 5)

I'm using the "Print Using" command, and it's fine otherwise, but I'd like that zero to be there.

Code: (Select All)
'timer

s = 0
Do
    _Limit 5
    Cls
    s = s + 1
    If s > 59 Then
        m = m + 1
        s = 0
    End If
    tmp$ = "##:##"
    Locate 1, 1
    Print Using tmp$; m; s
    _Display
Loop
Reply
#2
tmp$ = "0#:##" ' NOPE! seems I remember some trick for 0's
Code: (Select All)
Do
    Cls
    Print Time$ ' in a loop
    _Delay .5
Loop Until _KeyDown(27)
b = b + ...
Reply
#3
Code: (Select All)
print left$("00", 2 - len(str$(m))) + ltrim$(str$(m)); ":"; left$("00", 2 - len(str$(s))) + ltrim$(str$(s))
Without "PRINT USING" and messy but it works.
Reply
#4
Not a PRINT USING fan, either...

Lots of ways to do it, this is fairly simple...

Code: (Select All)
'timer

s = 0
DO
    _LIMIT 5
    s = s + 1
    IF s = 60 THEN
        m = m + 1: IF m = 13 THEN m = 1
        s = 0
    END IF
    s$ = "00": m$ = "00"
    MID$(s$, 3 - LEN(LTRIM$(STR$(s)))) = LTRIM$(STR$(s))
    MID$(m$, 3 - LEN(LTRIM$(STR$(m)))) = LTRIM$(STR$(m))
    LOCATE 1, 1
    PRINT m$; ":"; s$
    _DISPLAY
LOOP

Pete
Reply
#5
Thanks for the responses. A bit of wrestling required to get that zero. Much appreciated!
Reply
#6
So the zero is already displayed. . . until it becomes double digits.   Rolleyes

Code: (Select All)
'timer

s = 0
Do
  _Limit 5
  Cls
  s = s + 1
  If s > 59 Then
    m = m + 1
    s = 0
  End If
  'tmp$ = "##:##"
  Locate 1, 1
  Print Using "##.0#"; m; s
  _Display
Loop

And - Not very elegant, but simple.  Tongue
Code: (Select All)
'timer

s = 0
Do
  _Limit 5
  Cls
  s = s + 1
  If s > 59 Then
    m = m + 1
    s = 0
  End If
  'tmp$ = "##:##"
  Locate 1, 1
  Print Using "##.0##"; m; s
  _Display
Loop
Reply
#7
I would use this:
Code: (Select All)
'timer

s = 0
Do
    _Limit 5
    Cls
    s = s + 1
    If s > 59 Then
        m = m + 1
        s = 0
    End If
    If m < 10 Then m$ = "0" + Right$(Str$(m), 1) Else m$ = Right$(Str$(m), 2)
    If s < 10 Then s$ = "0" + Right$(Str$(s), 1) Else s$ = Right$(Str$(s), 2)


    Locate 1, 1
    Print m$; ":"; s$
    _Display
Loop
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#8
Is this what your looking for?

Code: (Select All)
'timer

s = 0
DO
  _LIMIT 5
  CLS
  s = s + 1
  IF s > 59 THEN
    m = m + 1
    s = 0
  END IF
  tmp$ = CHR$((48 * -(m <= 9)) + (35 * -(m > 9))) + "#:" + CHR$((48 * -(s <= 9)) + (35 * -(s > 9))) + "#"
  LOCATE 1, 1
  PRINT USING tmp$; m; s
  _DISPLAY
LOOP
Reply
#9
(11-02-2022, 12:36 AM)justsomeguy Wrote: Is this what your looking for?

Code: (Select All)
'timer

s = 0
DO
  _LIMIT 5
  CLS
  s = s + 1
  IF s > 59 THEN
    m = m + 1
    s = 0
  END IF
  tmp$ = CHR$((48 * -(m <= 9)) + (35 * -(m > 9))) + "#:" + CHR$((48 * -(s <= 9)) + (35 * -(s > 9))) + "#"
  LOCATE 1, 1
  PRINT USING tmp$; m; s
  _DISPLAY
LOOP

This is what I was planning to do and thought I'd ask first  Big Grin

Just in case there was some time/clock format command that existed for this purpose. I like all the different approaches suggested so far, but the chr$ version is the only one I had in mind before asking.
Reply
#10
Thumbs Up 
Quote:Is this what your looking for?

It is working! But mighty, mighty complicated Egon, Sven would say. - I made it understanding for myself (Learned something again):

Code: (Select All)
'Zeitanzeige. Problem mit "0" geloest (der einzige Weg?)
'justsomeguy - 2. Nov. 2022

Option _Explicit

Dim As Integer m, s
Dim As String tmp

s = 0: m = 0
Do
  _Limit 5
  Cls
  s = s + 1
  If s > 59 Then
    m = m + 1
    s = 0
  End If
  tmp = Chr$((48 * -(m <= 9)) + (35 * -(m > 9))) + "#:" + Chr$((48 * -(s <= 9)) + (35 * -(s > 9))) + "#"
  Locate 1, 1
  Print Using tmp$; m; s
  _Display
Loop While m < 2

End
Reply




Users browsing this thread: 3 Guest(s)