473,545 Members | 2,657 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I add numbers into a static array to a running total? This is for VB 6.0

5 New Member
I'm having some trouble coding this and I found myself very stumped. This is my code so far. I know I made some errors because it won't run correctly.

Expand|Select|Wrap|Line Numbers
  1. 'intTemp Program
  2. Option Explicit
  3.  
  4. Private Sub cmdCalc_Click()
  5.  
  6. Dim intTemp() As Integer
  7. ReDim intTemp(7) As Integer
  8. Dim intNum As Integer
  9. Dim dblSum As Double
  10. Dim dblAverage As Double
  11. Dim intCounter As Integer
  12.  
  13. txtNum.Text = intNum
  14.  
  15. If intCounter = 0 Then
  16. intCounter = intCounter + 1
  17. End If
  18.  
  19. If intCounter = 1 Then
  20. intTemp(0) = intNum
  21. ElseIf intCounter = 2 Then
  22. intTemp(1) = intNum
  23. ElseIf intCounter = 3 Then
  24. intTemp(2) = intNum
  25. ElseIf intCounter = 4 Then
  26. intTemp(3) = intNum
  27. ElseIf intCounter = 5 Then
  28. intTemp(4) = intNum
  29. ElseIf intCounter = 6 Then
  30. intTemp(5) = intNum
  31. ElseIf intCounter = 7 Then
  32. intTemp(6) = intNum
  33. ElseIf intCounter = 8 Then
  34. intTemp(7) = intNum
  35. End If
  36.  
  37.  
  38. dblSum = intTemp(0) + intTemp(1) + intTemp(2) + intTemp(3) + intTemp(4) + intTemp(5) + intTemp(6) + intTemp(7)
  39. lblSum.Caption = dblSum
  40. lblAverage.Caption = dblSum / intTemp(7)
  41.  
  42. Print intTemp(7)
  43.  
  44. End Sub
  45.  
Apr 30 '14 #1
8 1720
Luk3r
300 Contributor
Call me crazy, but something here has to change:
Expand|Select|Wrap|Line Numbers
  1. txtNum.Text = intNum
You specify that intNum is an integer, but you never give it a value. And if you want intNum to gain the value of the number you enter in txtNum, then your code should be flipped:

Expand|Select|Wrap|Line Numbers
  1. intNum = txtNum.Text
Apr 30 '14 #2
Blarghanaught
5 New Member
Thanks man, is there anything else I have to change or do to make the program work?
May 6 '14 #3
Luk3r
300 Contributor
You tell me :) Follow my suggestion and report back.
May 6 '14 #4
Blarghanaught
5 New Member
I followed it, but it still doesn't work so far. I find it funny that I made that mistake. :P I hope I'll be able to fix it soon... >_<
May 8 '14 #5
Luk3r
300 Contributor
You also need to make your integers global. That will ensure that when they are set to a value they will retain the value of the textbox.
May 8 '14 #6
Blarghanaught
5 New Member
Do you know which variables to set to Global? I'm guessing you mean these:
Expand|Select|Wrap|Line Numbers
  1. Dim intNum As Integer
  2. Dim dblSum As Double
  3. Dim dblAverage As Double
  4. Dim intCounter As Integer
  5.  
Should it be intNum and dblSum? Or is it just one?
May 8 '14 #7
Luk3r
300 Contributor
I would put all Integers global. You also have to change your logic for how "intCounter " gets changed. You only ever specify criteria once where it will change from 0 to 1. In your large If..Else statement you need to tell intCounter to change from 1 to 2, 2 to 3, 3 to 4, etc.

Expand|Select|Wrap|Line Numbers
  1.  If intCounter = 1 Then
  2. intTemp(0) = intNum
  3. intCounter = intCounter + 1
  4. ElseIf intCounter = 2 Then
  5. intTemp(1) = intNum
  6. intCounter = intCounter + 1
  7. ElseIf intCounter = 3 Then
  8. intTemp(2) = intNum
  9. intCounter = intCounter + 1
  10. ....and so on
May 8 '14 #8
Blarghanaught
5 New Member
Okay, I've done that! Hm.. I tried running the program just to see what would happen and I got this error: 'Compile Error: Invalid attribute in Sub or Function' And it highlighted Public intNum as Integer.
May 9 '14 #9

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

Similar topics

4
10336
by: Bill Dika | last post by:
Hi I am trying to calculate a running total of a calculated textbox (tbAtStandard) in GroupFooter1 for placement in a textbox (tbTotalAtStandard) on my report in Groupfooter0. The problem that I am having is that sometimes the correct total shows up in print preview and sometimes it doesn't. Sometimes it is higher and sometimes it is...
16
2422
by: StenKoll | last post by:
Help needed in order to create a register of stocks in a company. In accordance with local laws I need to give each individual share a number. I have accomplished this by establishing three tables (se below) then I run a query giving me a running total, which give me the first stock in the batch purchased by an individual, then I use this...
7
2550
by: Shannan Casteel via AccessMonster.com | last post by:
I have a form for entering part numbers along with the associated quantity for each part. There are 25 Part fields and 25 associated Quantity fields. If I go to record 1 and enter part number 1234 for part1, 3 for quantity1, and 1235 for part2, 8 for quantity2, and on record 2 I enter 1236 for part1, 2 for quantity1, and 1234 for part2, 2 for...
15
4848
by: Charles Sullivan | last post by:
Assume I have a static array of structures the elements of which could be any conceivable mixture of C types, pointers, arrays. And this array is uninitialized at program startup. If later in the program I wish to return this array to its startup state, can this be accomplished by writing binary zeroes to the entire memory block with...
16
11282
by: Gandalf186 | last post by:
I need to create a query that produces running totals for every group within my table for example i wish to see: - Group A 1 5 9 15 Group B
6
4865
by: Stuart Shay | last post by:
Hello All: I have a array which contains the totals for each month and from this array I want to get a running total for each month decimal month = new decimal; month = 254; (Jan) month = 78; (Feb) month = 34; (Mar) ect ...
11
7676
by: C C++ C++ | last post by:
Hi all, got this interview question please respond. How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Rgrds MA
1
2258
by: Bruce | last post by:
I had a form with a running total working until I was asked to add some checkboxes. Here is what I have: http://www.bearzilla.net/test/Untitled-1.html The first section works, but I can't get any part of "Make Additional Donation" add to the total. When I do get that part to work, then the 1st part for "Lunch" doesn't work. You can view...
3
2091
by: =?Utf-8?B?UGF1bA==?= | last post by:
Hi I have a webform with several entry boxes and the user enters numbers in each box. I keep a running total (just adds all of the entries together) but am posting back to the server to do this. Is there any way to do it all on the client side, without posting back to the server? I would like to update the running total each time the user...
6
11180
by: fishercraigj | last post by:
How do I code variables for a simple "running total" box without using an array? IE: I have a "Points Earned" text box that the user inputs a value into. I have another output "Total Points Earned" box that keeps a running count of all points earned every time the user inputs a new value. I've been doing this (which is obviously wrong): ...
0
7496
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7428
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7941
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7784
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6014
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5071
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.