CGAnimator Posted May 15, 2009 Share Posted May 15, 2009 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 More sharing options...
Triblade Posted May 15, 2009 Share Posted May 15, 2009 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 More sharing options...
Malkey Posted May 15, 2009 Share Posted May 15, 2009 (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 May 15, 2009 by Malkey Link to comment Share on other sites More sharing options...
Tomb Posted May 15, 2009 Share Posted May 15, 2009 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 Link to comment Share on other sites More sharing options...
Yuraj Posted May 15, 2009 Share Posted May 15, 2009 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) Link to comment Share on other sites More sharing options...
CGAnimator Posted May 15, 2009 Author Share Posted May 15, 2009 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 Link to comment Share on other sites More sharing options...
weaponx Posted May 15, 2009 Share Posted May 15, 2009 your codes was really genius Its all described in the help file. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now