Results 1 to 12 of 12

Thread: Functions RESOLVED

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Location
    Maine
    Posts
    23

    Thumbs up Functions RESOLVED

    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:
    1. Option Explicit
    2. Private Sub cmdCompute_Click()
    3. Dim n1 As Single, n2 As Single, n3 As Single
    4. Dim avg As Single
    5. Dim GrA As Single, GrB As Single, GrC As Single, GrD As Single
    6. Dim Res As String
    7. Res = "N/A"
    8. n1 = txtGr1.Text
    9. n2 = txtGr2.Text
    10. n3 = txtGr3.Text
    11. Rank n1, n2, n3
    12. lblGr1.Caption = n1
    13. lblGr2.Caption = n2
    14. lblGr3.Caption = n3
    15. avg = (n1 + n2 + n3) / 3
    16. lblRes.Caption = Round(avg)
    17. GrA = (90 - (avg * 0.6)) / 0.4
    18. GrB = (80 - (avg * 0.6)) / 0.4
    19. GrC = (70 - (avg * 0.6)) / 0.4
    20. GrD = (60 - (avg * 0.6)) / 0.4
    21. lblGrA.Caption = FormatNumber(GrA, 1)
    22. lblGrB.Caption = FormatNumber(GrB, 1)
    23. lblGrC.Caption = FormatNumber(GrC, 1)
    24. lblGrD.Caption = FormatNumber(GrD, 1)
    25. If GrA > 100 Then
    26.     lblGrA.Caption = Res
    27. End If
    28.    
    29. End Sub
    30.  
    31. Private Sub Rank(ByRef x As Single, ByRef y As Single, ByRef z As Single)
    32. 'Order scores from low (Gr1) to high (Gr3)
    33.     If x > y Then Swap x, y
    34.     If y > z Then Swap y, z
    35.     If x > y Then Swap x, y
    36. End Sub
    37.  
    38. Private Sub Swap(ByRef n1 As Single, ByRef n2 As Single)
    39.     Dim temp As Single
    40.     temp = n1
    41.     n1 = n2
    42.     n2 = temp
    43. End Sub
    44.  
    45. Private Function Score(ByVal currAvg As Single, ByVal finalAvg As Single) As String
    46.   Score = (currAvg * 0.6) + (finalAvg * 0.4)
    47.    
    48.        
    49.        
    50.            
    51. End Function
    Last edited by ldyslp4; Nov 4th, 2002 at 06:20 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width