VB Code:
Option Explicit
Private Sub cmdCompute_Click()
Dim n1 As Single, n2 As Single, n3 As Single
Dim avg As Single
Dim GrA As Single, GrB As Single, GrC As Single, GrD As Single
Dim Res As String
Res = "N/A"
n1 = txtGr1.Text
n2 = txtGr2.Text
n3 = txtGr3.Text
Rank n1, n2, n3
lblGr1.Caption = n1
lblGr2.Caption = n2
lblGr3.Caption = n3
avg = (n1 + n2 + n3) / 3
lblRes.Caption = Round(avg)
GrA = (90 - (avg * 0.6)) / 0.4
GrB = (80 - (avg * 0.6)) / 0.4
GrC = (70 - (avg * 0.6)) / 0.4
GrD = (60 - (avg * 0.6)) / 0.4
lblGrA.Caption = FormatNumber(GrA, 1)
lblGrB.Caption = FormatNumber(GrB, 1)
lblGrC.Caption = FormatNumber(GrC, 1)
lblGrD.Caption = FormatNumber(GrD, 1)
If GrA > 100 Then
lblGrA.Caption = Res
End If
End Sub
Private Sub Rank(ByRef x As Single, ByRef y As Single, ByRef z As Single)
'Order scores from low (Gr1) to high (Gr3)
If x > y Then Swap x, y
If y > z Then Swap y, z
If x > y Then Swap x, y
End Sub
Private Sub Swap(ByRef n1 As Single, ByRef n2 As Single)
Dim temp As Single
temp = n1
n1 = n2
n2 = temp
End Sub
Private Function Score(ByVal currAvg As Single, ByVal finalAvg As Single) As String
Score = (currAvg * 0.6) + (finalAvg * 0.4)
End Function