Jump to content
Sign in to follow this  
huldu

Simple math and Arrays

Recommended Posts

I was just wondering how do you do math using arrays?

For example:

$array[1]= 10

$array[2] = 20

$array[3] = 30

$array[4] = 40

$array[5] = 50

How would i "add" them together without doing this, $array[1] + $array[2] + $array[3] etc.

If we use a For loop, how would the adding part look?

For $x = 1 To UBound($array)
$sum = $array[$x] ?
?
Next

Thats pretty much what i got atm... :o


"I'm paper, rock is fine, nerf scissors!!!"

Share this post


Link to post
Share on other sites

I was just wondering how do you do math using arrays?

For example:

How would i "add" them together without doing this, $array[1] + $array[2] + $array[3] etc.

If we use a For loop, how would the adding part look?

For $x = 1 To UBound($array)
$sum = $array[$x] 
?
Next

Thats pretty much what i got atm... :o

For $x = 1 To UBound($array) - 1
$sum = $sum + $array[$x] 
Next
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Share this post


Link to post
Share on other sites

Dim $i, $sum, $array[5]
$array[0] = 1
$array[1] = 2
$array[2] = 3
$array[3] = 4
$array[4] = 5
$sum = 0
For $i = 0 to ubound($array, 1) - 1
$sum = $sum + $array[$i]
Next
msgbox(0,'',$sum)

That 'ought to work, havent tested it.

~cdkid

**edit**

gar, too slow

Edited by cdkid

AutoIt Console written in C#. Write au3 code right at the console :D_FileWriteToLineWrite to a specific line in a file.My UDF Libraries: MySQL UDF Library version 1.6 MySQL Database UDF's for AutoItI have stopped updating the MySQL thread above, all future updates will be on my SVN. The svn location is:kan2.sytes.net/publicsvn/mysqlnote: This will still be available, but due to my new job, and school hours, am no longer developing this udf.My business: www.hirethebrain.com Hire The Brain HireTheBrain.com Computer Consulting, Design, Assembly and RepairOh no! I've commited Scriptocide!

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...