Open
Description
It's common to see boolean assignments like this on SO:
Dim dayOfMonthIsEven As Boolean
If Day(Now()) Mod 2 = 0 Then
dayOfMonthIsEven = True
Else
dayOfMonthIsEven = False
End If
But that's 5 lines of code to resolve the boolean condition and assign a boolean value, that can be achieved more efficiently, concisely and clearly, in a single line assignment:
Dim dayOfMonthIsEven As Boolean
dayOfMonthIsEven = Day(Now()) Mod 2 = 0
RD should be able to identify these long-winded assignments, and rewrite them more efficiently as a boolean expression.
We'll also need to identify the equivalent single line If statement:
If Day(Now()) Mod 2 = 0 Then dayOfMonthIsEven = True Else dayOfMonthIsEven = False
And also need to identify the equivalent IIf
statement:
dayOfMonthIsEven = IIf(Day(Now()) Mod 2 = 0, True, False)
RD would also need to account for the reversed boolean logic that might require the expression to be flipped with a Not
operator (or some other expression adjustment):
Dim dayOfMonthIsEven As Boolean
If Day(Now()) Mod 2 = 1 Then
dayOfMonthIsEven = False
Else
dayOfMonthIsEven = True
End If
Could become:
dayOfMonthIsEven = Not Day(Now()) Mod 2 = 1
Or better still (although this would be much harder):
dayOfMonthIsEven = Day(Now()) Mod 2 = 0