formatting text to include leading 0's 
Author Message
 formatting text to include leading 0's

Hello:
Is there a way to format a text string similiar to VB's
format$ function?. I would like to include leading zero's.
I have looked at formatnumber and formatcurrency but I
don't think they let me decide how many leading zeros to
use.

Les F



Sun, 23 Nov 2003 11:23:07 GMT  
 formatting text to include leading 0's
Les F. says:

Quote:
>Is there a way to format a text string similiar to VB's
>format$ function?. I would like to include leading zero's.
>I have looked at formatnumber and formatcurrency but I
>don't think they let me decide how many leading zeros to
>use.

It's not hard to make your own.   Or you can use mine:
http://www.serverscripting.com/info.asp?id=1027

----------
Randy Hunt
MCP+I / MCSE

Please visit my web sites for free scripts!
http://www.serverscripting.com
http://www.wshscripting.com



Sun, 23 Nov 2003 14:35:16 GMT  
 formatting text to include leading 0's
Try the function below, where the parameter TheNumber can be either a
string or number, and the parameter Amount is the number of leading
zeroes to add.

Function AddLeadingZeroes(TheNumber,Amount)
    AddLeadingZeroes = String(Amount,"0") & TheNumber
End Function


| Hello:
| Is there a way to format a text string similiar to VB's
| format$ function?. I would like to include leading zero's.
| I have looked at formatnumber and formatcurrency but I
| don't think they let me decide how many leading zeros to
| use.
|
| Les F
|
|



Sun, 23 Nov 2003 14:50:17 GMT  
 formatting text to include leading 0's
Here is a pair of functions I use. The first is written to pad a numeric
"Value" with zeros so that it is 4 characters long. The second one actually
does the work. It is generic and can pad any value (numeric or string) using
any character (not just zero) to any length.

'---------------------
  Function AddLeadingZeros(Value)
    If Len(Value) < 4 And IsNumeric(Value) then
      Value = Pad(Value, 4, 0)
    End If
    AddLeadingZeros = Value
  End Function

'---------------------
  Function Pad(Value, Width, Char)
    Pad = Right(String(Width, CStr(Char)) & CStr(Value), Width)
  End Function


Quote:
> Hello:
> Is there a way to format a text string similiar to VB's
> format$ function?. I would like to include leading zero's.
> I have looked at formatnumber and formatcurrency but I
> don't think they let me decide how many leading zeros to
> use.

> Les F



Sun, 23 Nov 2003 22:25:42 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Convert MSDOS-text Format into contemporary text format

2. How to import an display Short-Date to include leading zero

3. Can't include japanese char in VB text-box

4. Package and Deployment Wizard won't include subfolders and text files

5. Passing text Values with 's included (Truncation)

6. Way to format a number with leading zeroes?

7. Passing text Values with 's included (Truncation)

8. How to format a number that is without thousand separator and with leading zeros

9. Want leads on large format postscript printers/plotters

10. Excel Xp VBA - Pad SSN's w/Leading Zero's

11. Help formatting longs with leading zeros

12. Formatting For Next with leading zeros

 

 
Powered by phpBB® Forum Software