Random observations of a very experienced software artist.

    Day of Week

    John McCann  February 29 2012 11:20:27 AM
    I picked up someone else's code today and saw a technique that struck me.   The application was set up to need a three character day of week.

    I look at the code and see the following construct:

           intDayOfWeek = Weekday(Now)
           Select Case intDayOfWeek
                   Case Is = 1
                           strDayOfWeek = "sun"
                   Case Is = 2
                           strDayOfWeek = "mon"
                   Case Is = 3
                           strDayOfWeek = "tue"
                   Case Is = 4
                           strDayOfWeek = "wed"
                   Case Is = 5
                           strDayOfWeek = "thu"
                   Case Is = 6
                           strDayOfWeek = "fri"
                   Case Is = 7
                           strDayOfWeek = "sat"
           End Select

    Besides the unnecessary "Is = ", something just nagged at me as there has got to be a better way.  Scratched around for a few minutes and came up with what I think is a simpler solution:

           strDayOfWeek = lcase$(format$(Now(),"ddd"))

    The found construct was only in one time initialization code, so performance effect is probably minimal - a slightly smaller module with execution difference smaller than the ticks with which you are measuring.  One could even argue that the first construct is clearer in what is being done so is more maintainable.  Something in me just likes the transforming solution.