Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format Number to "V00000000000"

Status
Not open for further replies.
Nov 29, 2002
64
US
Hello there,

How can I format a number into a string such as "V00000000000"

For example:
valor = 4736718 will return: V00004736718
valor = 82213944 will return: V00082213944

I guess it's with a function like
Code:
Selection.NumberFormat = "V00000000000"

but I can't figure it out...

Thanks a lot!
alfredo
 
Code:
'Usage: valor = "V" & padZeros(856942, 11)
Function padZeros(myNum, iMaxLen) 'returns string
    myNum = CStr(myNum)
    While Len(myNum) < iMaxLen
        myNum = "0" & myNum
    Wend
    padZeros = myNum
End Function

Good luck
 
yourstring = "V" & padder(Yournumber,10,0)

Function Padder(Source,PaddedLen,PadChar)
If Len(PadChar) > 1 Then Exit Function
If PadChar = "" Then
PadChar = " "
End If
Padder = Source
For PadPos = Len(Source) To PaddedLen - 1
Padder = PadChar & Padder
Next
End Function

[thumbsup2]DreX
aKa - Robert
 
My turn :)
Code:
yourString = "V" & PadString(yourNumber,10,"0")

Function PadString(origNumber, targetLength, padChar)
   PadString = origNumber
   If len(origNumber) < targetLength Then PadString = String(targetLength - len(origNumber),padChar) & origNumber
End Function

Should scale better then looping with additional concatenations,

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top