iamtheky Posted September 10, 2010 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 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
MrMitchell Posted September 10, 2010 Posted September 10, 2010 $string = Execute(_arraytostring ($Array, "+"))
Mat Posted September 10, 2010 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
iamtheky Posted September 11, 2010 Author Posted September 11, 2010 Thanks. And thanks for the enumerating from array solution. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
maqleod Posted September 11, 2010 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
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