Jump to content

Recommended Posts

Posted

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"

Posted

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)

Posted (edited)

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
Posted

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
Posted

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

:)

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
  • Recently Browsing   0 members

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