Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_web_howto thread: Format


Message #1 by Andy@a... on Wed, 20 Feb 2002 09:42:27
Hi



I have a number returned from a datsbase and I have to display it on a 

page with leading zeros. IE if 4 is returned I have to display 0004.



I get type mismatch errors if I use format() and I can't get the leading 

zeros with FormatNumber().



I need to do this with ASP because I have to send an email receipt of the 

number in the correct format.



Any clues?



Andy Green
Message #2 by "phil griffiths" <pgtips@m...> on Wed, 20 Feb 2002 10:19:57
This came up recently.  A simple function like this will do the trick:



Function LeadZeros(lNum, lPadLength)

' e.g. LeadZeros(12, 4) = "0012"

  LeadZeros = CStr(lNum)

  If Len(LeadZeros) < lPadLength Then

    LeadZeros = String(lPadLength - Len(LeadZeros), "0") & LeadZeros

  End If

End Function



HTH

Phil

> Hi

> 

> I have a number returned from a datsbase and I have to display it on a 

> page with leading zeros. IE if 4 is returned I have to display 0004.

> 

> I get type mismatch errors if I use format() and I can't get the leading 

> zeros with FormatNumber().

> 

> I need to do this with ASP because I have to send an email receipt of 

the 

> number in the correct format.

> 

> Any clues?

> 

> Andy Green

  Return to Index