richietheprogrammer 0 Posted May 17, 2011 Hi guys, I am trying to grab a number from somewhere, and I want that if the number is less than 6 digits, to fill the rest with 0's. So if the digit is 1234, I want to grab 001234. Can anyone help me? I'd appreciate it ! Share this post Link to post Share on other sites
somdcomputerguy 103 Posted May 17, 2011 Maybe StringLen can be used? If they truly are numbers, don't forget to convert (to a string) first. And after. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Share this post Link to post Share on other sites
sahsanu 28 Posted May 17, 2011 I am trying to grab a number from somewhere, and I want that if the number is less than 6 digits, to fill the rest with 0's. So if the digit is 1234, I want to grab 001234. Hard way: #include <array.au3> Local $array[5] = ["123456","123","1","1234567","12345"] For $i=0 to UBound($array)-1 $len=StringLen($array[$i]) If $len < 6 Then For $j=$len+1 To 6 $array[$i]= 0 & $array[$i] Next EndIf Next _ArrayDisplay($array) Easy way?: #include <array.au3> Local $array[5] = ["123456","123","","1234567","12345"] For $i=0 to UBound($array)-1 $array[$i]=StringFormat("%06s",$array[$i]) Next _ArrayDisplay($array) Share this post Link to post Share on other sites
richietheprogrammer 0 Posted May 17, 2011 Thanks, thats the easy part. So far I have: $number=inputbox("","","") if stringlen($number) < 6 Then $amountof0s= 6-stringlen($number) msgbox(0,"", $amountof0s&$number) EndIf This gives me the number of 0's, not the actual 0's. For example if I put 123, it will say "3123". How can I get it to say "000123"? Thanks again Share this post Link to post Share on other sites
richietheprogrammer 0 Posted May 17, 2011 Hard way: #include <array.au3> Local $array[5] = ["123456","123","1","1234567","12345"] For $i=0 to UBound($array)-1 $len=StringLen($array[$i]) If $len < 6 Then For $j=$len+1 To 6 $array[$i]= 0 & $array[$i] Next EndIf Next _ArrayDisplay($array) Easy way?: #include <array.au3> Local $array[5] = ["123456","123","","1234567","12345"] For $i=0 to UBound($array)-1 $array[$i]=StringFormat("%06s",$array[$i]) Next _ArrayDisplay($array) Thanks for this. I can see that it works with the given array, but how can we make that array a variable? Share this post Link to post Share on other sites
richietheprogrammer 0 Posted May 17, 2011 Well, this works. #include <array.au3> $answer=inputbox("","") Local $array[1] = [$answer] For $i=0 to UBound($array)-1 $array[$i]=StringFormat("%06s",$array[$i]) Next _ArrayDisplay($array) Share this post Link to post Share on other sites
richietheprogrammer 0 Posted May 18, 2011 Well, this works. #include <array.au3> $answer=inputbox("","") Local $array[1] = [$answer] For $i=0 to UBound($array)-1 $array[$i]=StringFormat("%06s",$array[$i]) Next _ArrayDisplay($array) But instead of _ArrayDisplay($array), how can I Msgbox($array)? Share this post Link to post Share on other sites
sahsanu 28 Posted May 18, 2011 But instead of _ArrayDisplay($array), how can I Msgbox($array)? I've used an array just as an example, you can use whatever you want. $answer = inputbox("","") $answer = StringFormat("%06s",$answer) MsgBox(0,"",$answer) Share this post Link to post Share on other sites
richietheprogrammer 0 Posted May 18, 2011 I've used an array just as an example, you can use whatever you want. $answer = inputbox("","") $answer = StringFormat("%06s",$answer) MsgBox(0,"",$answer) Hehe, I was about to paste that same code Thanks again!! Share this post Link to post Share on other sites