[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Count 00, 01, 02... in vbscript

Posted on 2012-09-05
5
Medium Priority
?
488 Views
Last Modified: 2012-09-13
Hey

Is there a more elegant way to count ... 00, 01, 02, 03... in vbscript


i = 0
do while i <= 20

if i < 10 then
wscript.echo "0" & i
else
wscript.echo i
end if

i = i + 1
loop
0
Comment
Question by:mikeydk
  • 3
  • 2
5 Comments
 
LVL 59

Accepted Solution

by:
Bill Prew earned 1000 total points
ID: 38369565
Not a lot better, but you could do:


for i=1 to 20
   wscript.echo Right("0" & i, 2)
loop

~bp
0
 
LVL 50

Assisted Solution

by:Martin Liss
Martin Liss earned 1000 total points
ID: 38369915
This is probably faster

For i = 1 to 9
    wscript.echo "0" & i
Next
For i = 10 to 20
    wscript.echo i
Next

Open in new window

0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 38370756
@Martin,

Yes, from a pure performance point of view, that would be "faster".  But it really depends on the usage.  If it really is just to generate the numbers then I might lead toward the single loop approach, since there's likely some logic inside the loop to execute, and I wouldn't want to repeat that twice.  But we'd need more info on the use case.

For what it's worth, for the 1...20 loop, I did a test of each approach, and they were both instance, taking essentially no time.  I had to do a loop of 10000 iterations around each approach to see some differences, and yes, the Right() approach took maybe .2 secs to run, compared to .1 for your dual loop approach.  Definitely faster, and if we had to do this a million times we'd clearly want the dual loop approach.

Thanks for the thoughts, good dialog!

~bp
0
 
LVL 50

Expert Comment

by:Martin Liss
ID: 38370810
You might be interested in my article of timing code.
0
 
LVL 59

Expert Comment

by:Bill Prew
ID: 38394418
Thanks, glad that was helpful.

~bp
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question