C
Carlo B
I need to store numbers in an array and by using a class I need to
calculate the average of the numbers entered. I cannot get the text box
to return the total of the numbers in the average function - it always
returns a 0.
What is wrong with this coding?
Thanks
Carlob1
Dim statistic(50) As statistics
Dim lastnumber As Integer
Private Sub btnRecord_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnRecord.Click
Dim st As statistics
st = New statistics()
lastnumber += 1
st.num = CDbl(txtNumber.Text)
statistic(lastnumber) = st
txtNumber.Text = 0
txtNumber.Focus()
End Sub
Private Sub btnAverage_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnAverage.Click
txtAverage.Text = statistic(lastnumber).average
End Sub
End Class
Class statistics
Private m_count As Integer
Private m_num As Double
Public total As Double
Public Property count() As Integer
Get
Return m_count
End Get
Set(ByVal Value As Integer)
m_count = Value
End Set
End Property
Public Property num() As Double
Get
Return m_num
End Get
Set(ByVal Value As Double)
m_num = Value
End Set
End Property
Sub addnumber(ByVal m_num)
total = m_num
total += total
End Sub
Function average() As Double
Dim av As Double
av = total
Return av
End Function
End Class
calculate the average of the numbers entered. I cannot get the text box
to return the total of the numbers in the average function - it always
returns a 0.
What is wrong with this coding?
Thanks
Carlob1
Dim statistic(50) As statistics
Dim lastnumber As Integer
Private Sub btnRecord_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnRecord.Click
Dim st As statistics
st = New statistics()
lastnumber += 1
st.num = CDbl(txtNumber.Text)
statistic(lastnumber) = st
txtNumber.Text = 0
txtNumber.Focus()
End Sub
Private Sub btnAverage_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnAverage.Click
txtAverage.Text = statistic(lastnumber).average
End Sub
End Class
Class statistics
Private m_count As Integer
Private m_num As Double
Public total As Double
Public Property count() As Integer
Get
Return m_count
End Get
Set(ByVal Value As Integer)
m_count = Value
End Set
End Property
Public Property num() As Double
Get
Return m_num
End Get
Set(ByVal Value As Double)
m_num = Value
End Set
End Property
Sub addnumber(ByVal m_num)
total = m_num
total += total
End Sub
Function average() As Double
Dim av As Double
av = total
Return av
End Function
End Class