Adding Numbers in an array to display as a running total

G

Guest

I cannot seem to find the right option for adding up numbers in an array. I
seem to have the bases of a solution, but some things need to be added so
that it functions properly. I need to see a running tally from the time that
I enter the 1st piece of data regardless of whether or not there is data in
the other text boxes on my form that are contained in an array.

I have tried establishing the array as both a variant and as an integer data
type and the integer gives the answer that I want, however it does work it
the other values are null. How do I get the array to read the empty values as
zero?

Here is my code:

Dim hours(10) As Integer 'An Array that contains hours.

Select Case IsNull(hours(10))
Case txtHours1
txtHours1 = 0
Case txtHours2
txtHours2 = 0
Case txtHours3
txtHour3 = 0
Case txtHours4
txtHours4 = 0
Case txtHours5
txtHours5 = 0
Case txtBPIHours
txtBPIHours = 0
Case txtTrainingHours
txtTrainingHours = 0
Case txtOutofOfficeHours
txtOutofOfficeHours = 0
Case txtHolidayHours
txtHolidayHours = 0
Case txtSwissArmyHours
txtSwissArmyHours = 0
Case txtOtherHours
txtOtherHours = 0
End Select

hours(0) = txtHours1
hours(1) = txtHours2
hours(2) = txtHours3
hours(3) = txtHours4
hours(4) = txtHours5
hours(5) = txtBPIHours
hours(6) = txtTrainingHours
hours(7) = txtOutofOfficeHours
hours(8) = txtHolidayHours
hours(9) = txtSwissArmyHours
hours(10) = txtOtherHours

BPITotalHours = hours(0) + hours(1) + hours(2) + hours(3) + hours(4) +
hours(5) + _
hours(6) + hours(7) + hours(8) + hours(9) + hours(10)
 
J

John Nurick

I have tried establishing the array as both a variant and as an integer data
type and the integer gives the answer that I want, however it does work it
the other values are null. How do I get the array to read the empty values as
zero?

Hi Jason,

hours(0) = Nz(txtHours1, 0)
...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top