473,419 Members | 1,581 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,419 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 69894
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.