Saturday, May 23, 2009

Creating User-Defined Functions Example program will automatically compute

The following program will automatically compute examination grades based on the marks that a student obtained. The code is shown on the right.





The Code

Public Function grade(mark As Variant) As String

Select Case mark
Case Is >= 80
grade = "A"
Case Is >= 70
grade = "B"
Case Is >= 60
grade = "C"
Case Is >= 50
grade = "D"
Case Is >= 40
grade = "E"
Case Else
grade = "F"
End Select

End Function



Private Sub compute_Click()

grading.Caption = grade(mark)



End Sub

No comments:

Post a Comment