tags:

views:

69

answers:

2

Hi,

How add leading zeroes to a number. For example

Dim stracctnumber as String

stracctnumber = 987654321

if stracctnumber is less than 15 characters, then add leading zeroes to the account number

so final number should be

stracctnumber = "000000987654321"

Can anyone help me.

Thanks

+2  A: 
strAcct = Right("000000000000000" & strAcct, 15)

Note that concatenation is relatively 'expensive'. If this is just for display, rather than modifying the underlying value, consider using the Format() function.

Stu
the thing is the stracct may change. Sometimes it will like 10 somtimes it will 12 or 13 or 9still it works?
pbrp
Try it out, and see.
pavium
+4  A: 
stracctnumber = Format(stracctnumber, String(15, "0"))
Jay Riggs
Works for numeric `stracctnumber` only. `Right(..., 15)` works for any string.
wqw
@wqw - question is "How add leading zeroes to a **number**"
MarkJ
@MarkJ: Dont believe it! Read the code: `Dim stracctnumber as String`
wqw