Print Using? - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://staging.qb64phoenix.com/forumdisplay.php?fid=10) +---- Thread: Print Using? (/showthread.php?tid=1031) |
RE: Print Using? - PhilOfPerth - 11-02-2022 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. RE: Print Using? - justsomeguy - 11-02-2022 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))) The negative outside the parenthesis flips the the sign to positive. Code: (Select All) Chr$((48 * 1) + (35 * 0)) 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 And you plug that into your string. RE: Print Using? - SMcNeill - 11-02-2022 Simple solution: Code: (Select All) 'timer RE: Print Using? - james2464 - 11-02-2022 Yeah that's actually perfect. RE: Print Using? - mdijkens - 11-02-2022 Code: (Select All) Print Right$("0" + LTrim$(Str$(m)), 2) + ":" + Right$("0" + LTrim$(Str$(s)), 2) RE: Print Using? - bplus - 11-02-2022 That's what I was thinking, print anywhere as one line function. RE: Print Using? - james2464 - 11-02-2022 I had no idea about str$() Thank you! RE: Print Using? - bplus - 11-02-2022 Str$( positive number) leaves a space on far left, that's why _trim$ is needed. RE: Print Using? - james2464 - 11-02-2022 (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 RE: Print Using? - Pete - 11-02-2022 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 |