# For Next getting the 0 in front of single numbers

## Recommended Posts

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
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 on other sites

```For \$x = 8 to 11
MsgBox(0, "hellow World", StringFormat("%02d", \$x))
Next```

##### Share on other sites

Here's one way:

```For \$x = 8 To 11
Next```

Edit: too slow, Helge beat me to it.

Edited by gafrost

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

##### Share on other sites

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
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

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.

##### 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

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...