Format text with leading zero's

fredp1fredp1 Member Posts: 86
Hi

I have a field on a report that is text that I want to have leading zero's.
The text is always a number and I want it be be a maximun of 3 charaters.
e.g
if the text = 4, it should print/display 004
if the text = 52, it should print/display 052
if the text = 152, it should print/display 152

If tried FORMAT(qtytext,0,'<TEXT,3><Filler Character,0>') but it adds the zero to the end.

How do I get it to have leading zero's

Thanks

Answers

  • AlbertvhAlbertvh Member Posts: 516
    Hi Fred,

    you could try this.
    Text := PADSTR('',3 - strlen(Text),'0') + Text;
    


    Albert
  • fredp1fredp1 Member Posts: 86
    Hi,

    It worked a treat! Thanks...

    If i didn't want a blank/zero value to be formated as 000, would i do something like this in a Report Sourceexpr?

    if text='', then text else PADSTR('',3 - STRLEN(Text,'0') +text;
  • ShedmanShedman Member Posts: 194
    What's wrong with?
    IF tekst <> '' THEN PADSTR(...
    
  • AlbertvhAlbertvh Member Posts: 516
    Hi,

    You could create a function in your report and use that function as the SourceExpr.

    MyFunction(Var Text)
    IF Text <> '' THEN
       Text := PADSTR('',MAXSTRLEN(Text) - STRLEN(Text),'0') + Text;
    

    SourceExpr MyFunction(Text)



    Albert
  • reijermolenaarreijermolenaar Member Posts: 256
    I don't think that will work. You need an exit value in your function:
    MyFunction(Text) : Text[1024]
    IF Text <> '' THEN
       EXIT(PADSTR('',MAXSTRLEN(Text) - STRLEN(Text),'0') + Text);
    
    Reijer Molenaar
    Object Manager
  • fredp1fredp1 Member Posts: 86
    Thanks to everyone that replied.

    All suggestions were great!
Sign In or Register to comment.