QB64 Phoenix Edition
Format$ - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Prolific Programmers (https://qb64phoenix.com/forum/forumdisplay.php?fid=26)
+---- Forum: SMcNeill (https://qb64phoenix.com/forum/forumdisplay.php?fid=29)
+---- Thread: Format$ (/showthread.php?tid=2554)



Format$ - SMcNeill - 03-30-2024

I swear, I'd posted this on the forums before, but I can't find it anymore on here.  (Maybe it's on the old forums from way back when?)

Anywho, with Rho and Eric both posting their functions to format text in a similar manner to Print Using, I thought I'd share this once again:

Code: (Select All)
Print Format(12345, "###,###")
Print Format(12345, "$###,###")
Print Format(Timer, "###,###.#####")


Function Format$ (num, using$)
    Static tempimage
    If tempimage = 0 Then tempimage = _NewImage(80, 1, 0)
    d = _Dest: s = _Source
    _Dest tempimage: _Source tempimage
    Cls
    Print Using using$; num;
    For i = 1 To 80
        p = Screen(1, i)
        If p = 0 Then Exit For
        text$ = text$ + Chr$(p)
    Next
    _Dest d: _Source s
    Format$ = text$
End Function



RE: Format$ - grymmjack - 03-31-2024

You should _FREEIMAGE tempimage somewhere too. I know it's static in the function, but you should maybe document that?

Also what screen mode is this using/depending on?


RE: Format$ - SMcNeill - 03-31-2024

(03-31-2024, 05:10 PM)grymmjack Wrote: You should _FREEIMAGE tempimage somewhere too. I know it's static in the function, but you should maybe document that?

Also what screen mode is this using/depending on?

In this case, I just figured it isn't worth the effort or overhead.  Our screen here is all of 160 bytes total in size.  Why create that, initialize it, free it, when we can just preserve and reuseit?

(It's a SCREEN 0 screen, 80 character, 1 row.  -NEWIMAGE(80, 1, 0) )

With memory usage this small, why waste cycles freeing it?  It preserve and reuse it.  Wink


RE: Format$ - bplus - 03-31-2024

(03-31-2024, 05:10 PM)grymmjack Wrote: You should _FREEIMAGE tempimage somewhere too. I know it's static in the function, but you should maybe document that?

Also what screen mode is this using/depending on?

tempimage = _NewImage(80, 1, 0)
this shows that it is screen 0 plus that is only screen you can use the Screen function to get letters.

ok steve beat to post time Wink

btw this was posted on the last forum, thats why it seems like deja vu


RE: Format$ - SMcNeill - 03-31-2024

I knew I'd shared it somewhere before!   Big Grin