Print Using?
#29
(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)

I'm using the "Print Using" command, and it's fine otherwise, but I'd like that zero to be there.
Back on topic, if solutions are still accepted. Resort to C/C++ for a solution. Smile

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.
Reply


Messages In This Thread
Print Using? - by james2464 - 11-01-2022, 11:39 PM
RE: Print Using? - by bplus - 11-01-2022, 11:45 PM
RE: Print Using? - by mnrvovrfc - 11-01-2022, 11:49 PM
RE: Print Using? - by Pete - 11-01-2022, 11:51 PM
RE: Print Using? - by james2464 - 11-02-2022, 12:03 AM
RE: Print Using? - by Kernelpanic - 11-02-2022, 12:23 AM
RE: Print Using? - by PhilOfPerth - 11-02-2022, 12:26 AM
RE: Print Using? - by justsomeguy - 11-02-2022, 12:36 AM
RE: Print Using? - by james2464 - 11-02-2022, 12:54 AM
RE: Print Using? - by Kernelpanic - 11-02-2022, 01:03 AM
RE: Print Using? - by PhilOfPerth - 11-02-2022, 01:33 AM
RE: Print Using? - by justsomeguy - 11-02-2022, 01:55 AM
RE: Print Using? - by SMcNeill - 11-02-2022, 02:51 PM
RE: Print Using? - by james2464 - 11-02-2022, 03:37 PM
RE: Print Using? - by mdijkens - 11-02-2022, 06:04 PM
RE: Print Using? - by bplus - 11-02-2022, 06:16 PM
RE: Print Using? - by james2464 - 11-02-2022, 06:22 PM
RE: Print Using? - by bplus - 11-02-2022, 06:25 PM
RE: Print Using? - by james2464 - 11-02-2022, 06:33 PM
RE: Print Using? - by Pete - 11-02-2022, 06:33 PM
RE: Print Using? - by james2464 - 11-02-2022, 06:43 PM
RE: Print Using? - by mnrvovrfc - 11-02-2022, 06:48 PM
RE: Print Using? - by Pete - 11-02-2022, 06:54 PM
RE: Print Using? - by TerryRitchie - 11-02-2022, 09:22 PM
RE: Print Using? - by james2464 - 11-02-2022, 06:51 PM
RE: Print Using? - by Kernelpanic - 11-02-2022, 10:36 PM
RE: Print Using? - by SMcNeill - 11-03-2022, 12:11 AM
RE: Print Using? - by Kernelpanic - 11-03-2022, 12:47 AM
RE: Print Using? - by mnrvovrfc - 11-03-2022, 12:07 PM
RE: Print Using? - by Kernelpanic - 11-03-2022, 03:26 PM
RE: Print Using? - by SpriggsySpriggs - 11-03-2022, 03:44 PM
RE: Print Using? - by bplus - 11-03-2022, 03:53 PM
RE: Print Using? - by Kernelpanic - 11-03-2022, 03:59 PM
RE: Print Using? - by SpriggsySpriggs - 11-03-2022, 04:36 PM
RE: Print Using? - by mnrvovrfc - 11-03-2022, 05:17 PM
RE: Print Using? - by SpriggsySpriggs - 11-03-2022, 05:59 PM
RE: Print Using? - by mnrvovrfc - 11-03-2022, 09:16 PM
RE: Print Using? - by bplus - 11-03-2022, 05:22 PM
RE: Print Using? - by mnrvovrfc - 11-03-2022, 05:32 PM
RE: Print Using? - by bplus - 11-03-2022, 05:57 PM
RE: Print Using? - by SMcNeill - 11-03-2022, 05:58 PM
RE: Print Using? - by Kernelpanic - 11-04-2022, 12:57 AM
RE: Print Using? - by mnrvovrfc - 11-04-2022, 03:47 PM



Users browsing this thread: 28 Guest(s)