Jump to content

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"

Link to comment
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)

Link to comment
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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...