Print Using?
#11
Incidentally, I guess you realize this, but the time is not measured in seconds as you have it. You need to add a _delay 1 (or slightly less) to get it to count in seconds.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Reply
#12
For those that are not sure how it works.
Code: (Select All)
tmp = Chr$((48 * -(m <= 9)) + (35 * -(m > 9))) + "#:" + Chr$((48 * -(s <= 9)) + (35 * -(s > 9))) + "#"

The minutes and seconds are essentially the same. So, I'll only explain the Boolean algebra portion.
Code: (Select All)
Chr$(48 * -(m <= 9)) + (35 * -(m > 9))

m <= 9 and m > 9 are mutually exclusive comparisons, that will return a 0 or a -1 and a -1 or 0, respectively .
Code: (Select All)
Chr$((48 * -(-1)) + (35 * -(0)))
or
Chr$((48 * -(0)) + (35 * -(-1)))

The negative outside the parenthesis flips the the sign to positive.
Code: (Select All)
Chr$((48 * 1) + (35 * 0))
or
Chr$((48 * 0) + (35 * 1))

48 is the ASCII character for '0' and 35 is the ASCII character for '#'
So, depending on the value of 'm' being greater or less than 9, you will get the value 48 or 35
Code: (Select All)
Chr$(48) '0
or
Chr$(35) '#

And you plug that into your string.
Reply
#13
Simple solution:

Code: (Select All)
'timer

s = 0
Do
    _Limit 5
    Cls
    s = s + 1
    If s > 59 Then
        m = m + 1
        s = 0
    End If

    Locate 1, 1: Print "00.00"
    m$ = _Trim$(Str$(m)): s$ = _Trim$(Str$(s))
    Locate 1, 3 - Len(m$): Print m$
    Locate 1, 6 - Len(s$): Print s$
    _Display
Loop
Reply
#14
Yeah that's actually perfect.
Reply
#15
Code: (Select All)
Print Right$("0" + LTrim$(Str$(m)), 2) + ":" + Right$("0" + LTrim$(Str$(s)), 2)
45y and 2M lines of MBASIC>BASICA>QBASIC>QBX>QB64 experience
Reply
#16
Thumbs Up 
That's what I was thinking, print anywhere as one line function.
b = b + ...
Reply
#17
I had no idea about str$()

Thank you!
Reply
#18
Str$( positive number) leaves a space on far left, that's why _trim$ is needed.
b = b + ...
Reply
#19
(11-02-2022, 06:25 PM)bplus Wrote: Str$( positive number) leaves a space on far left, that's why _trim$ is needed.

Thanks, I guess I'll have to mess around with these commands.

edit: nice to know about this

Code: (Select All)
m = 50500 + 3
a$ = Str$(m)
Print a$
Print LTrim$(a$)
Reply
#20
For number conversion, I've always used: LTRIM$(STR$(num))

It converts to string and removes any leading space. _TRIM$() trims on both ends, which is not needed with number conversion but is a nice addition as it saves time writing LTRIM$(RTRIM$(x$)) to trim off leading and trailing string spaces, if present.

Pete
Reply




Users browsing this thread: 3 Guest(s)