473,395 Members | 1,571 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 do I add numbers into a static array to a running total? This is for VB 6.0

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 1713
Luk3r
300 256MB
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
Thanks man, is there anything else I have to change or do to make the program work?
May 6 '14 #3
Luk3r
300 256MB
You tell me :) Follow my suggestion and report back.
May 6 '14 #4
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 256MB
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
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 256MB
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
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
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...
16
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...
7
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...
15
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...
16
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
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 =...
11
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
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...
3
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. ...
6
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...
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
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...
0
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,...

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.