473,395 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to sum the elements of an array?

Jim
What is the syntax for summing the elements of the an array and putting that
value into another varialble? Please.
Nov 20 '05 #1
10 69886
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

"Jim" <Ji*@Jones6148.freeserve.co.uk> wrote in message
news:u1**************@TK2MSFTNGP10.phx.gbl...
What is the syntax for summing the elements of the an array and putting that value into another varialble? Please.

Nov 20 '05 #2
"Jim" <Ji*@Jones6148.freeserve.co.uk> schrieb
What is the syntax for summing the elements of the an array and
putting that value into another varialble? Please.


Write a loop.
--
Armin

Nov 20 '05 #3
Hello,

"Jim" <Ji*@Jones6148.freeserve.co.uk> schrieb:
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())
///

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet

Nov 20 '05 #4
What is the syntax <of a loop> for summing the elements of the an array and putting that value into another varialble? Please.

Nov 20 '05 #5
Begin With "Colorful Toucan"
Follow your nose
End

"Fergus Cooney" <fi******@tesco.net> wrote in message
news:Ol**************@TK2MSFTNGP10.phx.gbl...
What is the syntax <of a loop> for summing the elements of the an array and putting that value into another varialble? Please.

Nov 20 '05 #6
?? Me not understand :-(
Nov 20 '05 #7
Hello,

"Fergus Cooney" <fi******@tesco.net> schrieb:
?? Me not understand :-(


Are you a newbie?

;-)

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #8
Hello,

"Fergus Cooney" <fi******@tesco.net> schrieb:
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.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
http://www.mvps.org/dotnet
Nov 20 '05 #9
Hi Herfried,

|| "Jim" <Ji*@Jones6148.freeserve.co.uk> schrieb
|| > What is the syntax for summing the elements of the an array and
|| > putting that value into another varialble? Please.
||
|| Write a loop.
||
|| Armin

|| "Fergus Cooney" <fi******@tesco.net> schrieb:
|| > 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

Nov 20 '05 #10
"Fergus Cooney" <fi******@tesco.net> schrieb
Hi Herfried,

|| "Jim" <Ji*@Jones6148.freeserve.co.uk> schrieb
|| > What is the syntax for summing the elements of the an array
and || > putting that value into another varialble? Please.
||
|| Write a loop.
||
|| Armin

|| "Fergus Cooney" <fi******@tesco.net> schrieb:
|| > 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, ...
--
Armin

Nov 20 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Mike S. Nowostawsky | last post by:
I tried using the "toUpperCase()" property to change the value of an array entity to uppercase BUT it tells me that the property is invalid. It seems that an array is not considered an object when...
1
by: Howard Jess | last post by:
Apparently, form elements of type <input type="image" src="...> are not included in the form's elements collection. I don't understand why not; according to DOM2, all form control elements...
4
by: WindAndWaves | last post by:
Hi Gurus I have the following statement in my code: var e = form.elements; Is it possible to put any conditions on this statement. What I actually want to say is: var e = form.elements...
9
by: Luke Wu | last post by:
Hello, I'm having some problems understanding 2 dimensional arrays. My problem relates to the following code: #include <stdio.h> #define M 3 #define N 3
5
by: jtougas | last post by:
What is the way to the type of an array's elements? Array a = new long { 1, 2, 3 }; Type t = a.GetType(); Console.WriteLine( t.FullName ); This will write "System.Int64", but is not what I'm...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
3
by: Areric | last post by:
Hey all, Anyone have any idea what im doing wrong here: $image = new Image(); $image->SetImageContent($imageRow); $image->SetFileSize($imageRow); $image->SetFileName($imageRow);...
14
by: rocketman768 | last post by:
Man, that title should be in a poem, but anyways...So, I have this program, and it has an array of 40 million elements. The problem is that I have a for loop that continually is doing stuff to this...
34
by: Luke | last post by:
Hi! I am new to PHP but I am a very experienced in Perl/CGI/templates. I work in medical informatics when we deal with very large data collection forms. Some of them have over 1000 elements!...
7
by: Christof Warlich | last post by:
Hi, the subject says it all: I need to instantiate an array of objects where each object "knows" its arrary index. So far, this is easy as long as index is not a compile-time constant: class ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.