i am trying to pass and array to a function in a module so i can calculate the average with multiple entries and its not keeping the other entries only the lat entry. in the function i tried different way to see if i can get the private array and it doesnt work. any idea how to get the private array into the function for multiple entries any ideas
Module Module1
Private nBath(9) As Integer
Private nPeople(9) As Integer
Private nIncome(9) As Integer
Private nHouse(9) As Integer
Public Sub ProcessHouse(ByVal nHouse As Integer, ByVal nBath As Integer, ByVal nPeople As Integer, ByVal nIncome As Double, ByRef lstHouse As ListBox, ByRef txtAvgBath As TextBox, ByRef txtAvgPeople As TextBox, ByRef txtAvgIncome As TextBox)
lstHouse.Items.Add("House: " & nHouse & " People: " & nPeople & " Baths: " & nBath & " Income: $" & nIncome)
txtAvgBath.Text = CalAvgBath(nHouse, nBath, lstHouse, txtAvgBath)
'txtAvgBath.Text = CalAvgBath(nHouse, nBath, lstHouse)
End Sub
Private Function CalAvgBath(ByRef nHouse As Integer, ByRef nBath As Integer, ByRef lstHouse As ListBox, ByRef txtAvgBath As TextBox)
Dim sumBath() As Integer
Dim avgBath As Integer
ReDim Preserve sumBath(nBath)
CalAvgBath = avgBath
'1st way
For i = 0 To sumBath.GetUpperBound(0)
If i = sumBath(i) Then
avgBath = sumBath(i)
Else
sumBath(i) += nBath
avgBath = sumBath(i) / nHouse
End If
Next
txtAvgBath.Text = avgBath
''2nd way
'For i As Integer = 0 To sumBath.GetUpperBound(0)
' If i = sumBath(i) Then
' avgBath = sumBath(i)
' Else
' avgBath = sumBath(i) / nHouse
' End If
'Next
'txtAvgBath.Text = avgBath
'3rd way
'For i As Integer = 0 To sumBath.GetUpperBound(0)
' 'If i = nBath Then
' 'avgBath = sumBath(i) / nHouse
' 'End If
'Next
'avgBath = sumBath(0) / nHouse
'Return avgBath
End Function
End Module