CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Oct 2006
    Posts
    10

    Conditionally inserting lead zeros

    I've searched through the forums, but can't find an answer specifically to what the results I'm trying to return.

    The data in each column I'm returning is of varying lengths, i.e.:

    123
    1234
    12345

    I need to return results that conform to a set character length; let's say 10 characters total, i.e.:

    0000000123
    0000001234
    0000012345

    I've tried replicatestring, but that returns a set amount of whichever value you insert into the formlua, while I need it to conform to the result.

    Any help would be GREATLY appreciated.

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Conditionally inserting lead zeros

    Try Format()
    Code:
    msgbox (Format(rst.num,"#########")
    000000123
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Oct 2006
    Posts
    10

    Re: Conditionally inserting lead zeros

    You'll have to excuse me dglienna, I'm a bit of a noob. Would I be formatting the specific field, or creating a formula using the field to drop in?

    If a formula, would it be:

    format({dp_correction.check_no}, "##########")

  4. #4
    Join Date
    May 2006
    Posts
    324

    Re: Conditionally inserting lead zeros

    right(replicatestring("0", 10) & totext({table.field}, 0, ""), 10)

  5. #5
    Join Date
    Oct 2006
    Posts
    10

    Re: Conditionally inserting lead zeros

    That worked Jagan, thanks so much!

    If I may, can I trouble you for one last issue?

    One of the fields returns a dollar amount. Using the formula you provided, I came up with the following:

    right(replicatestring("0", 10) & totext({dp_correction.amt},2,""), 10)

    I understand that the '2' in the formula allows for two places after the decimal, but I need to completely remove the decimal from the result.

    Is this possible?

    Thanks again.

  6. #6
    Join Date
    Jun 2006
    Posts
    38

    Lightbulb Re: Conditionally inserting lead zeros

    Code:
    right(replace(replicatestring("0", 10) & totext({dp_correction.amt},2,""),".",""), 10)
    Try that?

  7. #7
    Join Date
    Oct 2006
    Posts
    10

    Re: Conditionally inserting lead zeros

    Wenin, that worked perfectly! I can't thank you enough.

    Don't know if I can ever return the favor, but let me know if I can.

    Thanks again.

  8. #8
    Join Date
    Jun 2006
    Posts
    38

    Re: Conditionally inserting lead zeros

    I'm just happy to be able to give back to this forum that I've gotten plenty of assistance from in the past. =)

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

Featured