richietheprogrammer Posted May 17, 2011 Share 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 ! Link to comment Share on other sites More sharing options...
somdcomputerguy Posted May 17, 2011 Share 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. Link to comment Share on other sites More sharing options...
sahsanu Posted May 17, 2011 Share 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) Link to comment Share on other sites More sharing options...
richietheprogrammer Posted May 17, 2011 Author Share 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 Link to comment Share on other sites More sharing options...
richietheprogrammer Posted May 17, 2011 Author Share 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? Link to comment Share on other sites More sharing options...
richietheprogrammer Posted May 17, 2011 Author Share 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) Link to comment Share on other sites More sharing options...
richietheprogrammer Posted May 18, 2011 Author Share 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)? Link to comment Share on other sites More sharing options...
sahsanu Posted May 18, 2011 Share 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) Link to comment Share on other sites More sharing options...
richietheprogrammer Posted May 18, 2011 Author Share 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!! 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