I seem to think that this program might be a little off the mark when it comes to doing a function properly. Can anyone look at the code I have produced and see. It is supposed to take in 3 grade scores, display them from smallest to largest and tell you what the grade average is, then it is supposed to tell you what grade is required to get a (60=D,70=C,80=B,90=A) and if the grade is above 100 N/A will be displayed. Mine works but I was afraid I was missing the mark with the function since I really don't have any code under the function part.
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




Reply With Quote