I'm looking for some equivalent code that will convert a number using a mask
and store the result into a string.

In VBA: stringvar = Format$(I,"000") returns a 3 digit string. I.E.
when I = 1; "001" is the result. Its just like the Text(I,"000") function
that excel uses.

How is this done in VBScripting?

I have tried the FormatNumber() function but the 2nd parm that deals with
leading zeroes, is a boolean var parameter that doesn't do what I need.

--
Regards,
John

Re: number formating into a string by Torgeir

Torgeir
Fri Jul 22 11:09:49 CDT 2005

John Keith wrote:

> I'm looking for some equivalent code that will convert a number using a mask
> and store the result into a string.
>
> In VBA: stringvar = Format$(I,"000") returns a 3 digit string. I.E.
> when I = 1; "001" is the result. Its just like the Text(I,"000") function
> that excel uses.
>
> How is this done in VBScripting?
>
> I have tried the FormatNumber() function but the 2nd parm that deals with
> leading zeroes, is a boolean var parameter that doesn't do what I need.
>
Hi,

This is one way:

'--------------------8<----------------------

WScript.Echo Pad(1, "000")
WScript.Echo Pad(11, "000")
WScript.Echo Pad(111, "000")


Function Pad(vInput, sMask)
Pad = Right(sMask & vInput, Len(sMask))
End Function

'--------------------8<----------------------

--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx