Posts: 229
Threads: 25
Joined: Aug 2022
Reputation:
23
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
Posts: 3,974
Threads: 177
Joined: Apr 2022
Reputation:
219
11-01-2022, 11:45 PM
(This post was last modified: 11-01-2022, 11:56 PM by bplus.)
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 + ...
Posts: 1,586
Threads: 59
Joined: Jul 2022
Reputation:
52
11-01-2022, 11:49 PM
(This post was last modified: 11-01-2022, 11:54 PM by mnrvovrfc.
Edit Reason: Forgot the colon LOL
)
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.
Posts: 2,171
Threads: 222
Joined: Apr 2022
Reputation:
103
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
Posts: 229
Threads: 25
Joined: Aug 2022
Reputation:
23
Thanks for the responses. A bit of wrestling required to get that zero. Much appreciated!
Posts: 1,002
Threads: 50
Joined: May 2022
Reputation:
27
So the zero is already displayed. . . until it becomes double digits.
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.
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
Posts: 652
Threads: 96
Joined: Apr 2022
Reputation:
22
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
Posts: 128
Threads: 17
Joined: Apr 2022
Reputation:
10
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
Posts: 229
Threads: 25
Joined: Aug 2022
Reputation:
23
11-02-2022, 12:54 AM
(This post was last modified: 11-02-2022, 12:55 AM by james2464.)
(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
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.
Posts: 1,002
Threads: 50
Joined: May 2022
Reputation:
27
11-02-2022, 01:03 AM
(This post was last modified: 11-02-2022, 01:09 AM by Kernelpanic.)
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
|