Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Format$
#1
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
Reply
#2
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?
grymmjack (gj!)
GitHubYouTube | Soundcloud | 16colo.rs
Reply
#3
(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
Reply
#4
(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
b = b + ...
Reply
#5
I knew I'd shared it somewhere before!   Big Grin
Reply




Users browsing this thread: 1 Guest(s)