# Can Variable Be 0000 Instead of 0 ?

## Recommended Posts

I want to input some numbers from 0000 to 1001 in an input box

but variable don't accept this format .

here is a sample code

```\$vol = 0000
while \$vol < 1000
MsgBox (0,"",\$vol)
\$vol = \$vol + 0001
WEnd```

I get a message with "1", "2", "3" Instad of "0001", "0002", "0003"

##### Share on other sites

That's because in integers (numbers) leading zero's don't really exist.

If you would use it as text, that's a different story. It would probably be "0000" if you set: \$vol = "0000".

But when you do \$vol + 0001 AutoIt automatically detects it as a integer and set the variable as such.

The only thing I -as a AutoIt semi-noob- can think of is if you ONLY have a maximum of 4 numbers loop it to add leading zero's if needed.

```While StringLen(\$vol) < 4
\$vol = "0" & \$vol
WEnd```

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

##### Share on other sites

I want to input some numbers from 0000 to 1001 in an input box

but variable don't accept this format .

here is a sample code

```\$vol = 0000
while \$vol < 1000
MsgBox (0,"",\$vol)
\$vol = \$vol + 0001
WEnd```

I get a message with "1", "2", "3" Instad of "0001", "0002", "0003"

Try this.

```;
Local \$vol = 0
While \$vol < 12
MsgBox(0, "\$vol = " & \$vol, StringFormat("%04.0f", \$vol))
\$vol += 1
WEnd
;```

Edit: And another way.

```;
\$vol = 0
While \$vol < 12
MsgBox(0, "", StringRight("000" & \$vol, 4))
\$vol += 1
WEnd
;```
Edited by Malkey

##### Share on other sites

Something I thought of that should work.

```\$vol = 0
\$Num = ""

while \$vol < 1000
\$Length = StringLen(\$vol)
\$Count = 4 - \$Length
For \$o = 1 to \$Count
\$Num = \$Num & "0"
Next
MsgBox (0,"",\$Num & \$vol)
\$vol = \$vol + 1
\$Num = ""
WEnd```

##### Share on other sites

This is the best solution for you:

```\$vol = 0
while \$vol < 10
MsgBox (0,"",StringFormat("%04d",\$vol))
\$vol += 1
WEnd```

ShellExecute("http://www.yuraj.ucoz.com")ProcessClose(@AutoItPID)

##### Share on other sites

thank you all

a really good ideas came here

Thanks Triblade for the explain .

Thanks it works .

Thanks Tomb .

Thank you Malkey and Yuraj , your codes was really genius

thank you all

##### Share on other sites

Its all described in the help file.

## Create an account

Register a new account

×

• Wiki

• Back

• Git