Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Print Using?
#21
I clearly skipped a lesson in the QB64 tutorial

https://www.qb64tutorial.com/lesson9
Reply
#22
Navigated to that link, and started to read that tutorial, and noticed "_RTRIM$". Maybe it should be "_TRIM$" (without the "R").
Reply
#23
Yeah I'm going through it now and wondered the same thing.
Reply
#24
(11-02-2022, 06:48 PM)mnrvovrfc Wrote: Navigated to that link, and started to read that tutorial, and noticed "_RTRIM$". Maybe it should be "_TRIM$" (without the "R").

@TerryRitchie

Good catch by mn, + 1. That should be changed in your tutorial when you can get around to it.

Pete
Reply
#25
(11-02-2022, 06:54 PM)Pete Wrote:
(11-02-2022, 06:48 PM)mnrvovrfc Wrote: Navigated to that link, and started to read that tutorial, and noticed "_RTRIM$". Maybe it should be "_TRIM$" (without the "R").

@TerryRitchie

Good catch by mn, + 1. That should be changed in your tutorial when you can get around to it.

Pete

Whoops! Fixed it, thanks for catching that guys.
Reply
#26
Quote:SMcNeill - Simple solution:

This solution is . . . smoother. But this: _Trim$(Str$(minute)) I have to take a good look at it again. Anyway, it took me some time to get your solution with Option _Explicit.
About _Limit: If I understood that correctly, then _Limit 5 does not correspond to reality. There _Limit 2 comes closer to reality.

Code: (Select All)
'Zeitanzeige. SMcNeill - 2. Nov. 2022
'Problem mit "Option _Explicit"
'Geloest mit "minute_str" als Dummy

Option _Explicit

Dim As Integer minute, sekunde
Dim As String minute_str, sekunde_str

sekunde = 0: minute = 0
Do
  _Limit 5
  Cls
  sekunde = sekunde + 1
  If sekunde > 59 Then
    minute = minute + 1
    sekunde = 0
  End If

  Locate 3, 4: Print "00.00"

  'Minuten- und Sekundenzahl in String umwandeln
  minute_str = Str$(minute)
  sekunde_str = Str$(sekunde)

  'Hier gab es Probleme mit den Integer-Variablen
  'Str$(m) funktionierte nicht
  minute_str = _Trim$(Str$(minute)): sekunde_str = _Trim$(Str$(sekunde))
  Locate 3, 6 - Len(minute_str): Print minute_str
  Locate 3, 9 - Len(sekunde_str): Print sekunde_str
  _Display
Loop While minute < 2

End
Reply
#27
@Kernelpanic _LIMIT 5 simply says to run the program only 5 times in a second. If you want it to correspond closer to reality, then change the addition to + 0.2 instead of + 1.

(Just keep in mind, these are floating point values and thus are imprecise and will get ever so slightly further from the actual time, as time rolls by. If you need real precision here, make everything integers, add by 2, and divide by 10 only at the display point of the process. Remove floating points from the program completely, if absolute precision is needed.)
Reply
#28
(11-03-2022, 12:11 AM)SMcNeill Wrote: @Kernelpanic _LIMIT 5 simply says to run the program only 5 times in a second.  If you want it to correspond closer to reality, then change the addition to + 0.2 instead of + 1. 

(Just keep in mind, these are floating point values and thus are imprecise and will get ever so slightly further from the actual time, as time rolls by.  If you need real precision here, make everything integers, add by 3, and divide by 10 only at the display point of the process.  Remove floating points from the program completely, if absolute precision is needed.)

Thanks! I only noticed that the time is running out too fast. But if one really want it, or need it, your information is very helpful.
Reply
#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
#30
Quote:mnrvovrfc - 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.

Thanks, the clock runs well. But even if both files are in the same directory, the full path must still be specified; at least at me.
Code: (Select All)
Declare Library "D:\Lab\QuickBasic64\Extern\Libraries\hourminsec"
  Sub hourminsec (ByVal h As Integer, Byval m As Integer, Byval s As Integer, sout As String)
End Declare

[Image: Trotzdem-Kompletter-Pfad2022-11-03.jpg]
Reply




Users browsing this thread: 3 Guest(s)