[RESOLVED] padding zeroes for integers or strings
Good day.... I am trying to pad zeroes to a 5 digit ID number..
instead of 123, 4356, 78995, I would like to see 00123, 04356, 78995
Below doesn't seem to work:
My_String = SPrintF("%5d", xvalue)
or
MyString = String$((5 - Len (str$(xvalue))), "0") & str$(xvalue)
Thanks in advance,,,,,
Re: padding zeroes for integers or strings
You can have
MyString = String$(5 - Len(CStr(x)), "0") & CStr(x)
or
MyString = Right$("00000" & CStr(x), 5)
but you will have a truncated string if x has more than 5 digits.
However, you may want that, otherwise use this:
MyString = Format$(x, "00000")
Re: padding zeroes for integers or strings
hello anhn, thanks so much...
both lines work!
Re: padding zeroes for integers or strings
If you consider your question to be resolved please help us out by pulling down the Thread Tools menu and clicking the Mark Thread Resolved menu item. That will let everyone know that you have your answer.
Thank you. :)