0

I need a loop counter that starts at 001 and continues until the scripts reaches the end of the recordset. The counter needs to be displayed as:

001
002
003
004
005
006
007
008
009
010
011
012
013

etc...

It needs to be a fixed length of three characters and the number will never exceed 999.

Everytime I try this the counter ignores the zeros at the start and just counts like:

1
2
3
4
5
6

etc...

Can anybody help?

2 Answers 2

3

Or:

>> For Each i In Array(0, 1, 9, 11, 88, 101)
>>     WScript.Echo Right(1000 + i, 3)
>> Next
>>
000
001
009
011
088
101
>>
Sign up to request clarification or add additional context in comments.

Comments

1

There is probably an easier way to do this, but here is what I would do:

for i = 1 to 999
    if i > 99 then
        wscript.echo i
    elseif i > 9 then
        wscript.echo "0" & i
    else
        wscript.echo "00" & i
    end if
next

1 Comment

Thanks, I've basically done the same as your suggestion and it works fine now.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.