473,386 Members | 1,908 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,386 software developers and data experts.

adding in a loop

i need help on how to take the numbers u get in a loop, and add them
Oct 17 '06 #1
4 1891
willakawill
1,646 1GB
i need help on how to take the numbers u get in a loop, and add them
Could you give a little more information?
Oct 17 '06 #2
Killer42
8,435 Expert 8TB
Could you give a little more information?
I have to agree - more information, please
However, I'll try taking a "leap of faith"...

Create a variable to hold the result, and make sure it is zero before starting the loop. Then inside the loop, add the number to the result. For example...

Expand|Select|Wrap|Line Numbers
  1. Dim I as Long, J as Long
  2. FOR I = 1 To 10
  3.   J = J + I
  4. Next
  5.  
You should end up with the following values...
I = 11 (that's right, eleven - trust me on this)
J = 55

Perhaps this is something like what you were asking?
Oct 18 '06 #3
nym11
8
I have to agree - more information, please
However, I'll try taking a "leap of faith"...

Create a variable to hold the result, and make sure it is zero before starting the loop. Then inside the loop, add the number to the result. For example...

Expand|Select|Wrap|Line Numbers
  1. Dim I as Long, J as Long
  2. FOR I = 1 To 10
  3.   J = J + I
  4. Next
  5.  
You should end up with the following values...
I = 11 (that's right, eleven - trust me on this)
J = 55

Perhaps this is something like what you were asking?
I need help with somthing similar. I have to make a program with the 12 days of christmas. i am using 2 arrays, one with text and one with numbers that i have to add both using loops. Pretty much what i have to do is make 2 arrays one with text and one with prices and have them put in a number for a day. then say they put in 5 i need it to display 5 golden rings, 4 french hens... etc back up to 1 and then i have to have under that the total cost of all the items displayed. say a golden ring is 10 dollars i need it to do 10*5 and then add that to the price of what 4 french hens are and all the way down the line until the total is displayed. then after that i have to have a line displaying a price for all 12 days together.
Dec 12 '06 #4
Killer42
8,435 Expert 8TB
I need help with somthing similar. I have to make a program with the 12 days of christmas. i am using 2 arrays, one with text and one with numbers that i have to add both using loops. Pretty much what i have to do is make 2 arrays one with text and one with prices and have them put in a number for a day. then say they put in 5 i need it to display 5 golden rings, 4 french hens... etc back up to 1 and then i have to have under that the total cost of all the items displayed. say a golden ring is 10 dollars i need it to do 10*5 and then add that to the price of what 4 french hens are and all the way down the line until the total is displayed. then after that i have to have a line displaying a price for all 12 days together.
Um... I think I recall this thread, and someone suggested a two-dimensional array. You could also use two separate arrays. I'll throw together a little code snippet and see whether it helps.

Let's assume you have an array Description(1 to 12) As String containing the description of each day's item, and Price(1 To 12) As Single containing each item's individual price in dollars,
Expand|Select|Wrap|Line Numbers
  1. ' Assuming D = the selected day between 1 & 12
  2. Dim I as Long, Total As Single
  3. For I = 1 To D
  4.   Picture1.Print Description(I), Price(I) * I
  5.   Total = Total + Price(I) * I
  6. Next
  7. Picture1.Print "Total",Total
  8.  
Dec 12 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: David | last post by:
I have an array that contains numbers in string elements , i want to convert this to integers, i have made a for loop that uses the number of elements in the array and then adds 0, thereby...
1
by: - ions | last post by:
Hi, im a just wondering how to add elements into a JComboBox through a loop ie. just say i wanted to add the numbers 1 throught to 100. It seems easy but im having a bit of trouble. One problem...
4
by: Rhamphoryncus | last post by:
First a bit about myself. I've been programming in python several years now, and I've got several more years before that with C. I've got a lot of interest in the more theoretical stuff (language...
6
by: Paul M. | last post by:
Hi, I am trying to add a dataset to a list box on an asp .net page, the query results in about 20 rows coming back when I run it in access but when I loop through the dataset adding each records...
4
by: David Link | last post by:
Hi, Why does adding SUM and GROUP BY destroy performance? details follow. Thanks, David Link s1.sql: SELECT t.tid, t.title, COALESCE(s0c100r100.units, 0) as w0c100r100units,
5
by: Justin Fancy | last post by:
Hi everyone, I need some help. I'm placing text files into a created database using vb.Net. The problem is that, i need two seperate sql statements to add both files because they are in...
2
by: Justin Fancy | last post by:
Hi everyone, I need some help. I'm placing text files into a created database using vb.Net. The problem is that, i need two seperate sql statements to add both files because they are in...
5
by: Kosmos | last post by:
I have traveled the world and the seven seas and I have yet to come up with an answer to this question.... So I'm adding an attachment to an email from access... The following is the code: ...
2
by: _MC_ | last post by:
Hi, i want to structure two elements (each conists of 1 Label and 1 Textbox) in an Table. As I use an Content Place Holder, i thought it is possible to add the table via Controls.add(Literal)....
6
by: santiago | last post by:
I guess one cannot do this: arraytot = arraytot + arraydet; So, what's the trick to adding arrays like this? Thanks.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
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
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
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...

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.