Home > Archive > Visual Basic Syntax > January 2006 > Leading zero's
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Johnny 2006-01-23, 7:07 pm |
| Hi all, I have a question,
I'am writing increment number in a file wich reset after reaching 15.
I have code like below.
Dim counter
Counter =1
and at the end of the input i have the line
counter = counter +1
if counter = 16 then
counter =1
end if
All is fine so far but my output now is like below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
What I want is a leading zero that the output will be as follow:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
I hope that anybody do have a solution for me.
Thanks in advance.
Johnny
Data Manager
Mercurius Cards Company
Tel. (+31) 75-6476694
Fax.(+31) 75-6476676
Met vriendelijke groet,
Wim Langbroek
Data Manager
Mercurius Cards Company
Tel. (+31) 75-6476694
Fax.(+31) 75-6476676
mccdata@euronet.nl
| |
| Rick Rothstein [MVP - Visual Basic] 2006-01-23, 7:07 pm |
| > I'am writing increment number in a file wich reset after reaching 15.
>
> I have code like below.
>
> Dim counter
>
> Counter =1
>
> and at the end of the input i have the line
> counter = counter +1
> if counter = 16 then
> counter =1
> end if
>
> All is fine so far but my output now is like below:
>
> What I want is a leading zero that the output will be as follow:
Assuming you are okay in using a Variant data type for your Counter variable
(it is currently a Variant based on your Dim statement), then this you can
replace all of your code you posted (except for the Dim statement) with this
single line...
Counter = Format(1 + Counter Mod 15, "00")
Rick
| |
| Norm Cook 2006-01-23, 7:07 pm |
| Hmm, perhaps
Format$(counter, "00")
"Johnny" <tellnobody@at.all> wrote in message
news:43d4fd6c$0$4126$b83b6cc0@news.euronet.nl...
> Hi all, I have a question,
> I'am writing increment number in a file wich reset after reaching 15.
>
> I have code like below.
>
> Dim counter
>
> Counter =1
>
> and at the end of the input i have the line
> counter = counter +1
> if counter = 16 then
> counter =1
> end if
>
> All is fine so far but my output now is like below:
>
> 1
> 2
> 3
> 4
> 5
> 6
> 7
> 8
> 9
> 10
> 11
> 12
> 13
> 14
> 15
>
> What I want is a leading zero that the output will be as follow:
>
> 01
> 02
> 03
> 04
> 05
> 06
> 07
> 08
> 09
> 10
> 11
> 12
> 13
> 14
> 15
>
> I hope that anybody do have a solution for me.
>
> Thanks in advance.
> Johnny
>
> Data Manager
> Mercurius Cards Company
> Tel. (+31) 75-6476694
> Fax.(+31) 75-6476676
>
>
>
>
>
> Met vriendelijke groet,
> Wim Langbroek
> Data Manager
> Mercurius Cards Company
> Tel. (+31) 75-6476694
> Fax.(+31) 75-6476676
> mccdata@euronet.nl
>
>
>
| |
| Randy Birch 2006-01-26, 4:02 am |
| huh? if that executes inside a for/next loop, the loop will never end if
the To value is greater than 15.
--
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
Please reply to the newsgroups so all can participate.
"Rick Rothstein [MVP - Visual Basic]" <rickNOSPAMnews@NOSPAMcomcast.net>
wrote in message news:%23CkIDuDIGHA.516@TK2MSFTNGP15.phx.gbl...
:> I'am writing increment number in a file wich reset after reaching 15.
: >
: > I have code like below.
: >
: > Dim counter
: >
: > Counter =1
: >
: > and at the end of the input i have the line
: > counter = counter +1
: > if counter = 16 then
: > counter =1
: > end if
: >
: > All is fine so far but my output now is like below:
: >
: > What I want is a leading zero that the output will be as follow:
:
: Assuming you are okay in using a Variant data type for your Counter
variable
: (it is currently a Variant based on your Dim statement), then this you can
: replace all of your code you posted (except for the Dim statement) with
this
: single line...
:
: Counter = Format(1 + Counter Mod 15, "00")
:
: Rick
:
:
| |
| Rick Rothstein [MVP - Visual Basic] 2006-01-26, 4:02 am |
| > huh? if that executes inside a for/next loop,
> the loop will never end if the To value is
> greater than 15.
If will end in whatever way the OP currently ends his loop. Remember, I said
this one-liner would replace "all of your code you posted (except for the
Dim statement)". The code he posted was this...
> Dim counter
>
> Counter =1
>
> and at the end of the input i have the line
> counter = counter +1
> if counter = 16 then
> counter =1
My one-liner assigns the same values to the counter variable that the above
code does. However the OP is currently ending his program (using the code
that he did not show us), it should also end my one-liner too.
Rick
|
|
|
|
|