Format function problem

  • Thread starter Thread starter Howard
  • Start date Start date
H

Howard

Does anybody know how to get around the format of 10-digit
number?

Dim J As String
J=Format(CLng(123456789), "000000000000000") 'working
J=Format(CLng(1234567890), "000000000000000")'err:overflow
 
The example you provided (1234567890), works for me.

However, any 10 digit number greater than 2147483647 will cause Clng() to
fail since that is the limit of the Long data type.
 
Does anybody know how to get around the format of 10-digit
number?

Dim J As String
J=Format(CLng(123456789), "000000000000000") 'working
J=Format(CLng(1234567890), "000000000000000")'err:overflow

A Long Integer is limited to the range from -2147483648 to 2147483647,
so CLng() will fail on any ten digit number greater than this. It
should work on your example. Checking:

Yes:
?Format(CLng(1234567890), "000000000000000")
000001234567890
?Format(CLng(3234567890), "000000000000000")
<overflow error>

If you're trying to convert a string of digits to a fifteen-digit
string with leading zeros, you don't need numeric conversions at all:
instead use

Right("000000000000000" & [fieldname], 15)
 
Thanks, guys! I'm sorry I didn't give a right example. I
meant a 10 digit number, not 1234567890.
-----Original Message-----
Does anybody know how to get around the format of 10- digit
number?

Dim J As String
J=Format(CLng(123456789), "000000000000000") 'working
J=Format(CLng (1234567890), "000000000000000")'err:overflow

A Long Integer is limited to the range from -2147483648 to 2147483647,
so CLng() will fail on any ten digit number greater than this. It
should work on your example. Checking:

Yes:
?Format(CLng(1234567890), "000000000000000")
000001234567890
?Format(CLng(3234567890), "000000000000000")
<overflow error>

If you're trying to convert a string of digits to a fifteen-digit
string with leading zeros, you don't need numeric conversions at all:
instead use

Right("000000000000000" & [fieldname], 15)



.
 
Back
Top