Public Class frmMax

  Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
    'Calculate the maximum age at inauguration for the last 9 presidents
    Dim ages() As Integer = {55, 56, 61, 52, 69, 64, 46, 54, 47}
    txtOutput.Text = "The maximum age is " & Maximum(ages) & "."
  End Sub

  Function Maximum(ByVal ages() As Integer) As Integer
    Dim max As Integer = ages(0)
    For i As Integer = 1 To ages.Count - 1
      If ages(i) > max Then
        max = ages(i)
      End If
    Next
    Return max
  End Function

End Class
