Here's another little known way to use
Select Case.
In this case, an average is being derived at and
Ratings assigned accordingly. If the
PointAverage is above a certain value, the
Rating is thus and so.
If the
PointAverage was, for the sake of this demo, 6.0, then the Case expression would satisfy
every Case, because 6.0 is greater than 0, 1.5, 2.5, 3.5, 4.5 and 5.5! So which value is assigned to the control
Rating?
In the
Select Case construct, if a value satisfies more than one
Case, the
first Case that is satisfied is the one that is executed! To take advantage of this, you construct your
Select Case in
descending order, i.e. with the highest value first. So in this case,
Rating would be assigned "
U."
Likewise, with a
PointAverage of 4.7,
Rating would be assigned "
E" because
Case Is > 4.5 is the first
Case that 4.7 satisfies.
- Select Case PointAverage
-
Case Is > 5.5
-
Me.Rating = "U"
-
Case Is > 4.5
-
Me.Rating = "E"
-
Case Is > 3.5
-
Me.Rating = "D"
-
Case Is > 2.5
-
Me.Rating = "C"
-
Case Is > 1.5
-
Me.Rating = "B"
-
Case Is > 0
-
Me.Rating = "A"
-
End Select
Linq
;0)>