Sign in to follow this  
Followers 0
iamtheky

adding numbers from _arraytostring

5 posts in this topic

#1 ·  Posted (edited)

bunch of numbers in an array, i would like to add all these numbers together and output the sum. I have tried 'eval' , 'abs' , 'round' , and 'number' none of which result with desired output (I have also tried spaces and squiggly brackets around the plus sign in fear that the string was formatted incorrectly for math functions), any suggestions would be greatly appreciated. Thanks.

#Include <Array.au3>

Local $Array[10]

$Array[0] = "0"
$Array[1] = "1"
$Array[2] = "2"
$Array[3] = "3"
$Array[4] = "4"
$Array[5] = "5"
$Array[6] = "6"
$Array[7] = "7"
$Array[8] = "8"
$Array[9] = "9"

;~ _ArrayDisplay ($Array)

$string = _arraytostring ($Array, "+")

msgbox (0, '' , $string)

$sum = ???????($string)  ; can this $string be added??

msgbox (0, '' , $sum)
Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites



$string = Execute(_arraytostring ($Array, "+"))

Share this post


Link to post
Share on other sites

Why don't you just enumerate through the entries?

Local $Array[10]

$Array[0] = "0"
$Array[1] = "1"
$Array[2] = "2"
$Array[3] = "3"
$Array[4] = "4"
$Array[5] = "5"
$Array[6] = "6"
$Array[7] = "7"
$Array[8] = "8"
$Array[9] = "9"

$string = 0

For $i = 0 To UBound($Array) - 1
    $string += $Array[$i]
Next

msgbox (0, '' , $string)

Share this post


Link to post
Share on other sites

Thanks. And thanks for the enumerating from array solution.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

you can also do this to make the code a bit shorter

Local $Array[10] = [0,1,2,3,4,5,6,7,8,9]

[u]You can download my projects at:[/u] Pulsar Software

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