iamtheky 927 Posted September 10, 2010 (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 September 10, 2010 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Share this post Link to post Share on other sites
MrMitchell 16 Posted September 10, 2010 $string = Execute(_arraytostring ($Array, "+")) Share this post Link to post Share on other sites
Mat 376 Posted September 10, 2010 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) AutoIt Project Listing Share this post Link to post Share on other sites
iamtheky 927 Posted September 11, 2010 Thanks. And thanks for the enumerating from array solution. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Share this post Link to post Share on other sites
maqleod 1 Posted September 11, 2010 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