I’ve got the following that has got multiple values of a particular variable and I don’t want to stack up to a lot of IF ELSE statements to handle them, so I’d be grateful if some one could very kindly modify the code by using the SELECT CASE statement.
Also, I’d like dgMarksEntry.Item(7, i).Value and dgMarksEntry.Item(8, i).Value to handle RANK and COUNT the number of items entered respectively.
For i = 0 To 100
dgMarksEntry.Item(4, i).Value = Val(dgMarksEntry.Item(3, i).Value) + Val(dgMarksEntry.Item(2, i).Value)
If dgMarksEntry.Item(4, i).Value >= 80 Then
dgMarksEntry.Item(5, i).Value = "A1"
dgMarksEntry.Item(6, i).Value = "Excellent"
ElseIf dgMarksEntry.Item(4, i).Value >= 75 Then
dgMarksEntry.Item(5, i).Value = "B2"
dgMarksEntry.Item(6, i).Value = "Very good"
ElseIf dgMarksEntry.Item(4, i).Value >= 70 Then
dgMarksEntry.Item(5, i).Value = "B3"
dgMarksEntry.Item(6, i).Value = "Good"
ElseIf dgMarksEntry.Item(4, i).Value >= 65 Then
dgMarksEntry.Item(5, i).Value = "C4"
dgMarksEntry.Item(6, i).Value = "Credit"
ElseIf dgMarksEntry.Item(4, i).Value >= 60 Then
dgMarksEntry.Item(5, i).Value = "C5"
dgMarksEntry.Item(6, i).Value = "Credit"
ElseIf dgMarksEntry.Item(4, i).Value >= 55 Then
dgMarksEntry.Item(5, i).Value = "C6"
dgMarksEntry.Item(6, i).Value = "Credit"
ElseIf dgMarksEntry.Item(4, i).Value >= 50 Then
dgMarksEntry.Item(5, i).Value = "D7"
dgMarksEntry.Item(6, i).Value = "Pass"
ElseIf dgMarksEntry.Item(4, i).Value >= 40 Then
dgMarksEntry.Item(5, i).Value = "E8"
dgMarksEntry.Item(6, i).Value = "Weak pass"
ElseIf dgMarksEntry.Item(4, i).Value <= 39 Then
dgMarksEntry.Item(5, i).Value = "F9"
dgMarksEntry.Item(6, i).Value = "Fail"
End If
Next
I would choose a completely different approach. First, declare a class, which can contain rating information:
Then change your logic to:
With this approach, you could also read the rating information from a file or database. This makes it easier to change the limits. It is also less error prone, since the logic is programmed only once and is the same for all the limits.