|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Format a Numeric to include leading zerosHow do I format a numeric to include leading zeros? I want to do a loop
that will name files 099 down to 001. The zeros are getting dropped and I don't want them to. Thanks. Saucer Man wrote:
> How do I format a numeric to include leading zeros? I want to do a loop Dim n As Long> that will name files 099 down to 001. The zeros are getting dropped and I > don't want them to. Thanks. For n = 99 To 1 Step -1 Debug.Print Format(n, "000") Next n Mike "Saucer Man" <saucerman@nospam.net> wrote in message Dim sTmp = Format( nCnt, "000")news:NcedneTrJ_nWKsTeRVn-sw@adelphia.com... > How do I format a numeric to include leading zeros? I want to do a loop > that will name files 099 down to 001. The zeros are getting dropped and I > don't want them to. Thanks. > > Dim sTmp = Format( nCnt, "000") Not in VB6 (you can't assign values in a Dim statement).Rick "Rick Rothstein [MVP - Visual Basic]" <rickNOSPAMnews@NOSPAMcomcast.net> <That's the trouble with switching back and forth all day long.>wrote in message news:uDgLL7r1FHA.3560@TK2MSFTNGP15.phx.gbl... > > Dim sTmp = Format( nCnt, "000") > > Not in VB6 (you can't assign values in a Dim statement). > > Rick > Dim sTmp As String : sTmp = Format(nCnt, "000") Thanks all! I didn't realize the "000" would work for numerics.
-- Show quoteHide quoteThanks. "Saucer Man" <saucerman@nospam.net> wrote in message news:NcedneTrJ_nWKsTeRVn-sw@adelphia.com... > How do I format a numeric to include leading zeros? I want to do a loop > that will name files 099 down to 001. The zeros are getting dropped and I > don't want them to. Thanks. > > > > Saucer Man wrote:
> What would it work for then? (Curious about the comment as the only> Thanks all! I didn't realize the "000" would work for numerics. > ..... place "0" appears in the descriptions of formatting is in user-defined numeric formats.) "Duane Bozarth" <dpboza***@swko.dot.net> wrote in message Some examples show it as ...news:435B9FD1.A8FF7C59@swko.dot.net... > Saucer Man wrote: > > > > Thanks all! I didn't realize the "000" would work for numerics. > > > .... > > What would it work for then? (Curious about the comment as the only > place "0" appears in the descriptions of formatting is in user-defined > numeric formats.) Dim sTmp As String sTmp = Format("123", "0000") I've run into quite a few new students, who associate "Format" with String and Data formatting only and assume the seed string can only be a String or Date. Not trying to speak for the OP, but it does happen. -ralph Ralph wrote:
Show quoteHide quote > But that's still applying the "0000" format field to a numeric field.> "Duane Bozarth" <dpboza***@swko.dot.net> wrote in message > news:435B9FD1.A8FF7C59@swko.dot.net... > > Saucer Man wrote: > > > > > > Thanks all! I didn't realize the "000" would work for numerics. > > > > > .... > > > > What would it work for then? (Curious about the comment as the only > > place "0" appears in the descriptions of formatting is in user-defined > > numeric formats.) > > Some examples show it as ... > Dim sTmp As String > sTmp = Format("123", "0000") > > I've run into quite a few new students, who associate "Format" with String > and Data formatting only and assume the seed string can only be a String or > Date. > Not trying to speak for the OP, but it does happen. Observe the results of ?Format("abc", "0000") abc which demonstrates that again it's the silent VB type coercion in play here.
Show quote
Hide quote
"Duane Bozarth" <dpboza***@swko.dot.net> wrote in message Which would have been useful additional information for Saucer Man. Nownews:435C37BD.775CC3C7@swko.dot.net... > Ralph wrote: > > > > "Duane Bozarth" <dpboza***@swko.dot.net> wrote in message > > news:435B9FD1.A8FF7C59@swko.dot.net... > > > Saucer Man wrote: > > > > > > > > Thanks all! I didn't realize the "000" would work for numerics. > > > > > > > .... > > > > > > What would it work for then? (Curious about the comment as the only > > > place "0" appears in the descriptions of formatting is in user-defined > > > numeric formats.) > > > > Some examples show it as ... > > Dim sTmp As String > > sTmp = Format("123", "0000") > > > > I've run into quite a few new students, who associate "Format" with String > > and Data formatting only and assume the seed string can only be a String or > > Date. > > Not trying to speak for the OP, but it does happen. > > But that's still applying the "0000" format field to a numeric field. > Observe the results of > > ?Format("abc", "0000") > abc > > which demonstrates that again it's the silent VB type coercion in play > here. > isn't it fun to share? -ralph Ralph wrote:
Show quoteHide quote > I guess, and if I knew that were the question I'm sure I would> "Duane Bozarth" <dpboza***@swko.dot.net> wrote in message > news:435C37BD.775CC3C7@swko.dot.net... > > Ralph wrote: > > > > > > "Duane Bozarth" <dpboza***@swko.dot.net> wrote in message > > > news:435B9FD1.A8FF7C59@swko.dot.net... > > > > Saucer Man wrote: > > > > > > > > > > Thanks all! I didn't realize the "000" would work for numerics. > > > > > > > > > .... > > > > > > > > What would it work for then? (Curious about the comment as the only > > > > place "0" appears in the descriptions of formatting is in user-defined > > > > numeric formats.) > > > > > > Some examples show it as ... > > > Dim sTmp As String > > > sTmp = Format("123", "0000") > > > > > > I've run into quite a few new students, who associate "Format" with > String > > > and Data formatting only and assume the seed string can only be a String > or > > > Date. > > > Not trying to speak for the OP, but it does happen. > > > > But that's still applying the "0000" format field to a numeric field. > > Observe the results of > > > > ?Format("abc", "0000") > > abc > > > > which demonstrates that again it's the silent VB type coercion in play > > here. > > > > Which would have been useful additional information for Saucer Man. Now > isn't it fun to share? have...but I didn't (and still don't know what he meant...) :(
Error from Hell: Overflow
True type barcode font The Elements of Style revisited. How to access related documents in VB through source code? DataSource class help Please Explain! MSDN Library on network location Global (Public) variables Verify a signed integer as even or odd Object Model Extraction |
|||||||||||||||||||||||