Jump to content
Sign in to follow this  
CGAnimator

Can Variable Be 0000 Instead of 0 ?

Recommended Posts

CGAnimator

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


Link to post
Share on other sites
Triblade

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


Link to post
Share on other sites
Malkey

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


Link to post
Share on other sites
Tomb

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


Link to post
Share on other sites
CGAnimator

thank you all

a really good ideas came here :party:

Thanks Triblade for the explain .

Thanks it works .

Thanks Tomb .

Thank you Malkey and Yuraj , your codes was really genius :idea:

thank you all

:)

Share this post


Link to post
Share on other sites
weaponx

your codes was really genius :)

Its all described in the help file.

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.