Sign in to follow this  
Followers 0
richietheprogrammer

Number of characters

9 posts in this topic

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 :unsure: !

Share this post


Link to post
Share on other sites



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

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

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 :unsure:

Share this post


Link to post
Share on other sites

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

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

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

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

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 :unsure: Thanks again!!

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  
Followers 0