Adding * to the left of a field to fill a certain number of characters

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Vasago
    New Member
    • Mar 2014
    • 46

    Adding * to the left of a field to fill a certain number of characters

    I am working out my payroll system and would like * to the left of the field that has the check amount in "words"

    example:
    (Currently Showing)
    one thousand and five hundred dollar and 12 cents
    (Would like it to show)
    one thousand and five hundred dollar and 12 cents*********

    Another example
    (Currently Showing)
    ten dollars
    (Would like it to show)
    ten dollars******** *************** *************** ********

    I figured I would have to len(field) to find length of string then somehow fill it to "100" characters with * starting at left$(len(field )).

    My thought process might be way off.

    Thanks for your help,
    Vasago
  • jimatqsi
    Moderator Top Contributor
    • Oct 2006
    • 1293

    #2
    Vasago,
    Lots of ways to solve this one. Here's one
    Code:
    strAmount = Some$InWords
    do while len(strAmount)<100
    strAmount=strAmount & "*"  ' keep adding * until 100 chars long
    loop
    Jim

    Comment

    • zmbd
      Recognized Expert Moderator Expert
      • Mar 2012
      • 5501

      #3
      yuck loop.

      BTW: Title states to add to the left... the example adds to the right. (^_^)
      We can fix that (^_^)

      Working from your example:
      open the VBA editor

      <ctrl><g>
      Type the following into the immediates window.

      Code:
      strz = "abcd"
      ?strz
      abcd
      rplz = strz & string((100-len(strz)),"*")
      ?rplz
      abcd************************************************************************************************
      rplz = string((100-len(strz)),"*") & strz 
      ?rplz
      ************************************************************************************************abcd
      I'll leave it for you to code.
      Last edited by zmbd; May 22 '14, 09:41 PM.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32661

        #4
        Sorry to reset your answer Jim, but I'm afraid it wasn't a good one for the question. Using the String() function as illustrated in Z's post would be the obvious and standard approach.
        Last edited by NeoPa; May 25 '14, 11:33 AM. Reason: Typo

        Comment

        • jimatqsi
          Moderator Top Contributor
          • Oct 2006
          • 1293

          #5
          Well, you win some, you lose some. I don't believe I have ever used that String function. Many thanks to ZMBD for enlightening me on that one.

          Jim

          Comment

          • zmbd
            Recognized Expert Moderator Expert
            • Mar 2012
            • 5501

            #6
            Just swooping in before I start the long drive...

            Loop or String() either IMHO either is a solution.
            I remember a time when String() wasn't an option so keeping the loop in the bag-o-tricks is a good thing...


            (^_^)

            Comment

            Working...