Results 1 to 4 of 4

Thread: [RESOLVED] padding zeroes for integers or strings

  1. #1

    Thread Starter
    Junior Member Polgi-Wan's Avatar
    Join Date
    Sep 2001
    Location
    Oudenaarde
    Posts
    30

    Resolved [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,,,,,

  2. #2
    Head Hunted anhn's Avatar
    Join Date
    Aug 2007
    Location
    Australia
    Posts
    3,669

    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")
    • Don't forget to use [CODE]your code here[/CODE] when posting code
    • If your question was answered please use Thread Tools to mark your thread [RESOLVED]
    • Don't forget to RATE helpful posts

    • Baby Steps a guided tour
    • IsDigits() and IsNumber() functions • Wichmann-Hill Random() function • >> and << functions for VB • CopyFileByChunk

  3. #3

    Thread Starter
    Junior Member Polgi-Wan's Avatar
    Join Date
    Sep 2001
    Location
    Oudenaarde
    Posts
    30

    Cool Re: padding zeroes for integers or strings

    hello anhn, thanks so much...

    both lines work!

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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
  •  



Click Here to Expand Forum to Full Width