Public Class frmNames
Private names() As String = {"Bob", "Carroll", "Ted", "Alice"}
Private age(3) As Integer
Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStats.Click
'assign the ages
Me.GetAges()
'process the ages
Dim average As Decimal = Me.FigureAverageAge()
'display the results
Me.DisplayStats(average)
End Sub
'input
Private Sub GetAges()
age(0) = CInt(txtAge1.Text)
age(1) = CInt(txtAge2.Text)
age(2) = CInt(txtAge3.Text)
age(3) = CInt(txtAge4.Text)
End Sub
Private Function FigureAverageAge() As Decimal
Dim subTotal As Integer
'sum the ages
For index As Integer = 0 To age.GetUpperBound(0)
subTotal += age(index)
Next
Return CDec(subTotal / age.Length)
End Function
Private Function FigureOldest() As Integer
End Function
Private Sub DisplayStats(ByVal ageAverage As Decimal)
lblAge.Text = ageAverage.ToString
End Sub
Private Sub frmNames_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' the load event runs when the form is loaded into memory
txtName1.Text = names(0)
txtName2.Text = names(1)
txtName3.Text = names(2)
txtName4.Text = names(3)
End Sub
End Class
how do I find the oldest person in the array without sorting?
Attached File(s)
-
Names.zip (57.98K)
Number of downloads: 70

New Topic/Question
Reply




MultiQuote





|