11-03-2022, 12:07 PM
(11-01-2022, 11:39 PM)james2464 Wrote: 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)Back on topic, if solutions are still accepted. Resort to C/C++ for a solution.
I'm using the "Print Using" command, and it's fine otherwise, but I'd like that zero to be there.
This is a C header file, call it "hourminsec.h" (without double-quotation marks).
Code: (Select All)
void hourminsec (short h, short m, short s, char * sout)
{
sprintf(sout, "%02d:%02d:%02d", h, m, s);
}
This is the BASIC program, name it whatever you want, but place in the same directory as "hourminsec.h". Recommended both files on the same directory as QB64PE executable.
Code: (Select All)
declare library "hourminsec"
sub hourminsec(byval h as integer, byval m as integer, byval s as integer, sout as string)
end declare
'timer
Dim As Integer h, m, s
h = 0
s = 0
Do
_Limit 5
Cls
s = s + 1
If s > 59 Then
m = m + 1
s = 0
End If
Locate 1, 1
Print gethms$(h, m, s)
_Display
Loop
end
function gethms$ (h as integer, m as integer, s as integer)
dim sret$
sret$ = space$(20)
hourminsec h, m, s, sret$
gethms$ = sret$
end function
The function is for convenience, in case you just want to get a string value. If you don't want hour just use "MID$()" starting with fourth character, like you have to do with "TIME$".
I was going to suggest "strftime()" but that's more complicated if one doesn't want the "current time" returned as string. Otherwise it's just giving it "%H:%M:%S" as string input. There is an example program for it in the "man" page.