How to sum the elements of an array?

  • Thread starter Thread starter Jim
  • Start date Start date
J

Jim

What is the syntax for summing the elements of the an array and putting that
value into another varialble? Please.
 
Jim
VS.NET 2003 syntax

Dim a() As Integer = {1, 2, 3, 4, 5}
Dim sum As Integer
For Each item As Integer in a
sum += item
Next

Of course you change Integer to any data type you want.

If you do not care for For Each, you can use any other type of loop you
want.

Hope this helps
Jay
 
Hello,

Jim said:
What is the syntax for summing the elements of the an array
and putting that value into another varialble?

\\\
Dim aint() As Integer = {4, 5, 7, 99}
Dim sum As Integer
Dim i As Integer
For Each i In aint
sum = sum + i
Next i
MsgBox(sum.ToString())
///
 
What is the syntax <of a loop> for summing the elements of the an array and putting that value into another varialble? Please.
 
Begin With "Colorful Toucan"
Follow your nose
End

Fergus Cooney said:
What is the syntax <of a loop> for summing the elements of the an array
and putting that value into another varialble? Please.
 
Hello,

Fergus Cooney said:
What is the syntax <of a loop> for summing the elements of the
an array and putting that value into another varialble? Please.

Buy a beginner's book for the Visual Basic .NET language.
 
Hi Herfried,

|| > What is the syntax for summing the elements of the an array and
|| > putting that value into another varialble? Please.
||
|| Write a loop.
||
|| Armin

|| > What is the syntax <of a loop> for summing the elements of the
|| > an array and putting that value into another varialble? Please.

I was suggesting to Armin that with "Write a loop" he was being not
<quite> as helpful as he could have been.

Regards,
Fergus
 
Fergus Cooney said:
Hi Herfried,

|| > What is the syntax for summing the elements of the an array
and || > putting that value into another varialble? Please.
||
|| Write a loop.
||
|| Armin

|| > What is the syntax <of a loop> for summing the elements of
the || > an array and putting that value into another varialble?
Please.

I was suggesting to Armin that with "Write a loop" he was being
not
<quite> as helpful as he could have been.


Jim has not been <quite> as busy as he could have been. Consequently, ...
 
Back
Top