Print Using

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

Print Using

Post by PB&J Lover »

Let's face it, we need a print using that works. I tried the library versions and they don't work or operate the way a print using should.

We don't have to call it that and we are almost there with the FormatDate() comand. Just expand that. In fact, call it FormatText() and allow for the same sort of field substitutions. It wouldn't take much. :D

Code: Select all

Text$ = FormatText(" Total: $#,###.##",StrF(Total.f))
Something like this with other template options. :wink:
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

Hi PB&J Lover,

You say in your tagline you also use PureVision...
Have you looked at the PVGadgets_FormatNumber() command?
It might help you out a little.
Image Image
PB&J Lover
Enthusiast
Enthusiast
Posts: 212
Joined: Fri Apr 22, 2005 2:07 pm
Location: U.S.A.
Contact:

Post by PB&J Lover »

Paul, yes I do use it. Like it a lot. The documentation is not as complete as it should be though--I missed that one. :wink:
-- DB

Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage — to move in the opposite direction.

Albert Einstein
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> You say in your tagline you also use PureVision...
> Have you looked at the PVGadgets_FormatNumber() command?

Perhaps, but for those of us without PureVision it's a valid request. ;)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

dunno if this is of any use...

Code: Select all

Procedure.s x_strex(var.l,format.s)                                 ; convert int to string using a format field, format characters space and -+#.#
  Protected s.s, fl.l, sl.l, *f.BYTE, *s.BYTE, p.l, sb.l
  ;
  ; *** format integer to string
  ;
  ; in:  var.l    - int varar
  ;      f.s    - format
  ; out: .s    - string
  ;
  ; convert int varar to string using a pattern
  ;
  ; pattern elements:
  ;
  ; '#' - number or leading zero
  ; ' ' - space, number or (when there's no '+' or '-' used in the format) sign
  ; '+' - positive or negative indicator
  ; '.' - decimal sign
  ;
  ; examples:
  ;
  ; x_strex( 1234,     "###") =     "***"
  ; x_strex( 1234,   "##.##") =   "12.34"
  ; x_strex(-1234,   "##.##") =   "*****"
  ; x_strex(    1,  ".#####") =  ".00001"
  ; x_strex(   -1, "+   .##") = "-   .01"
  ;
  fl = Len(format)
  s = Str(var)
  sl = Len(s)
  ;
  *f.BYTE = @format+fl                               ; using two pointers and two counters
  *s.BYTE = @s+sl
  ;
  If PeekB(@format) = '+'                            ; remember is there is a sign in a fixed place
    p = 2
  ElseIf PeekB(@format) = '-'
    p = 1
  EndIf
  ;
  While fl > 0
    *f-1
    fl-1
    If *f\b = '.'                               ; skip a dot if we pass one
    Else
      sl-1
      If sl >= 0
        *s-1
        sb = *s\b                               ; sb contains the digit, AND is used as a flag
      EndIf
      Select *f\b
        Case '-'                                ; ah, a sign in a fixed place
          If sb = '-'
            sb = -1                             ; if sb = -1 we've managed to store the sign
          Else
            *f\b = ' '
          EndIf
        Case '+'                                ; same thing for the +
          If sb = '-'
            *f\b = sb
            sb = -1
          EndIf
        Case '#'                                ; if we have data that is not a sign we're gonna fill it in
          If sb = '-' Or sl < 0
            *f\b = '0'                          ; otherwise it's going to be a zero
          Else
            *f\b = *s\b
          EndIf
        Case ' '                                ; if there is no fixed spot for a sign we'll store the minus
          If sb = '-'                           ; immediately on the first space we encounter
            If p = 0
              *f\b = '-'
              sb = -1
            EndIf
          ElseIf sb <> -1 And sl >= 0           ; otherwise we'll just gonna fil it in
            *f\b = *s\b
          EndIf
      EndSelect
    EndIf
  Wend
  ;
  If sb = '-' Or sl > 0                         ; if the sign wasn't stored or there was some data left
    format = LSet("",Len(format),"*")           ; we'll put in some stars to indicate overflow
  EndIf
  ;
  ProcedureReturn format
EndProcedure
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

PB wrote: Perhaps, but for those of us without PureVision it's a valid request. ;)

Obvious solution.... get PureVision !! :D
Image Image
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Post by Paul »

PB&J Lover wrote:Paul, yes I do use it. Like it a lot. The documentation is not as complete as it should be though--I missed that one. :wink:
Unfortunately you actually have to read the documentation to see what commands are available. :)
Image Image
Post Reply