Sign in to follow this  
Followers 0
tAKTelapis

For Next getting the 0 in front of single numbers

5 posts in this topic

Hey guys,

i use this function a lot, when performing actions on remote computers.

computers are named:

xxx-Room-01

and so forth.

at the moment, whenever i create a For Next statement, i do the following:

For $x = 8 to 11
    $add0 = StringLen($x)
    If $add0 = 1 Then $x = String("0"&$x)
MsgBox(0, "hellow World", $x)
Next

is there any way to do this, and use less code ?

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

Here's one way:

For $x = 8 To 11
    $add0 = StringFormat("%02d", $x)
    MsgBox(0, "hellow World", $add0)
Next

Edit: too slow, Helge beat me to it.

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hey guys,

i use this function a lot, when performing actions on remote computers.

computers are named:

xxx-Room-01

and so forth.

at the moment, whenever i create a For Next statement, i do the following:

For $x = 8 to 11
    $add0 = StringLen($x)
    If $add0 = 1 Then $x = String("0"&$x)
MsgBox(0, "hellow World", $x)
Next

Edit:

That's kind of funny... like a machine going off with answers.

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

no... we run around 200 last count.

but each is in a different lab.. an no lab is over 30.. so 2 digits is fine.

thanks for the help guys, i had worked it into one line myself just after asking, i had this:

For $x = 8 to 11
If StringLen($x) = 1 Then $x = String("0"&$x)
MsgBox(0, "hellow World", $x)
Next

so i compressed my two lines into one, bu i guess the more proffessional way to go would be the string format.

Cheers

/tAK

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0