|
-
Aug 19th, 2008, 10:56 PM
#1
Thread Starter
Junior Member
[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,,,,,
-
Aug 19th, 2008, 11:22 PM
#2
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")
-
Aug 21st, 2008, 10:14 AM
#3
Thread Starter
Junior Member
Re: padding zeroes for integers or strings
hello anhn, thanks so much...
both lines work!
-
Aug 21st, 2008, 10:22 AM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|