locked
Leading zero for Recno() RRS feed

  • Question

  • I have a simple vfp9 program

    temp.dbf has 2 fields

    no (2 digits)  +  name

    I use the following code:

    replace all no with recno()

    It works perfectly except I want it to be 01, 02, 03 ...09 leading zero for the first 9 numbers.

    Help.

    Thanxs

     

    Friday, October 8, 2010 4:12 PM

Answers

  • replace all NO with padl(Recno(),2,'0')
    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    • Marked as answer by CaleCrow Friday, October 8, 2010 7:47 PM
    Friday, October 8, 2010 7:17 PM

All replies

  • The "no" column seems to be numeric, so leading zeros are possible to define in a mask when displaying data:

    BROWSE FIELDS no00=TRANSFORM(no, '@L 99'), name
    

     

    Friday, October 8, 2010 4:42 PM
  • Hi,

    I assume you  want to display the content of your table in your form mit leading zeros. And in that case you use the FORMAT property of your textbox.

    txtNo.Inputmask = 99

    txtNo.format = [L]

    This displays leading zeros instead of spaces in the text box.

     


    Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011
    Friday, October 8, 2010 4:42 PM
    Answerer
  • If you would need the leading zero stored in the table then the no column must be of character data type and the REPLACE command must contain TRANSFORM() function.

    BTW, why do you need to store information which is known for all records?

    Friday, October 8, 2010 4:44 PM
  • Hi CaleCrow,
     
    >> I want it to be 01, 02, 03 ...09 leading zero for the first 9 numbers.
     
    Numbers are numbers, and as such never have leading zeros.  I assume that you need that leading zero just for display purposes, thus just put a "L" into the Format property and a "99" into the Inputmask property of your textbox (or the column of a grid).
     
     

    wOOdy
    Microsoft Visual FoxPro Technology Advisor
    Microsoft "Most Valuable Professional" from 1996 to 2009
    Visit my XING profile! Don't know what XING is?

    *´¨)
    ¸.·´¸.·*´¨) ¸.·*¨)
    (¸.·´. (¸.·` *
    .·`.Visual FoxPro: It's magic !
    (¸.·``··*


     

    Friday, October 8, 2010 4:47 PM
  • I am just curious how do you all know CaleCrow uses some textboxes?  :-)

     

    Friday, October 8, 2010 4:53 PM
  • You're right,

    he could also use a label :-))))

    label.Caption = TRANSFORM(no, '@L 99')
    OR
    label.Caption = PADL(no,2,[0])

    Gruss / Best regards -Tom 010101100100011001010000011110000101001001101111011000110110101101110011
    Friday, October 8, 2010 5:02 PM
    Answerer
  • Hey, I also pointed to the Grid.Column ;)

     


    wOOdy
    Microsoft Visual FoxPro Technology Advisor
    Microsoft "Most Valuable Professional" from 1996 to 2009
    Visit my XING profile! Don't know what XING is?

    *´¨)
    ¸.·´¸.·*´¨) ¸.·*¨)
    (¸.·´. (¸.·` *
    .·`.Visual FoxPro: It's magic !
    (¸.·``··*


     

    Friday, October 8, 2010 5:53 PM
  • Okay I can make the field NO a 2 digit character field. (This program is a utility that creates a table for another program so I don't have a textbox or anything else. Right now the code I have is

    repl all NO with recno()

    If I change NO to a character field exactly what is the line exact line of code I need to insert. Where does the transform go????

    Thanks.

     

     

    Friday, October 8, 2010 6:42 PM
  • replace all NO with padl(Recno(),2,'0')
    Premature optimization is the root of all evil in programming. (c) by Donald Knuth

    Naomi Nosonovsky, Sr. Programmer-Analyst

    My blog
    • Marked as answer by CaleCrow Friday, October 8, 2010 7:47 PM
    Friday, October 8, 2010 7:17 PM
  • Hmm, it not so good if you are not able to update the REPLACE command when the field data type changes...

    I would recommend some VFP books, e.g.:
    http://www.ml-consult.co.uk/books.htm
    http://fox.wikis.com/wc.dll?Wiki~GoodVFPBooks
    http://www.amazon.com/s/ref=nb_sb_noss?url=search-alias%3Dstripbooks&field-keywords=foxpro&x=16&y=22

    Friday, October 8, 2010 9:00 PM