Results 1 to 3 of 3

Thread: Simple Question?

  1. #1

    Thread Starter
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Posts
    141
    I'm trying to build a dynamic string of zeros...
    ie. "0000000". I want to be able to supply the number of
    characters I need and then have the string generate.
    If I need 4 I would call a function and return "0000", if I need 10 I would call the function and return "0000000000".

    Is there a simple function similar to SPACE() function that allows you to supply the character you want repeated?

    I've got a couple of methods (shown below) but I'm looking for the fastest code.

    Code:
        'Method 1:  Use Space and Replace Functions
        Dim strTemp As String
        'I'm hard coding in a 6 for example purposes
        'Normally I'd pass the value in to the function
    
        strTemp = Space(6)
        strTemp = Replace(strTemp, " ", "0")
        
        'Method 2: Use for loop and append the string
        Dim strTemp As String
        Dim intCnt As Integer
        strTemp = ""
        For intCnt = 1 To 6
            strTemp = strTemp & "0"
        Next
    Any insight anyone can provide will be appreciated.
    JC

  2. #2
    Guest
    String(6, "0") 'returns "000000"



  3. #3

    Thread Starter
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Posts
    141

    Smile

    Thanks. I knew it had to be something simple like that.
    JC

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