Cleaner Code Part 1
- 0 0
-
shares
When revisiting old functions, you'll often find some truly brute force methods used, usually due to time restrictions and trying to push together a solution as quick as you can.
Something I recently came across was a quick UDF ( User defined function ) to return an integer month from a text string. This was used to select the correct month/year from a filename with an embedded date, partially as text ( 'DD-MMM-YY' format)
Previously , the code looked like this :
In this case, it's a simple range of integers, which could be turned into a loop instead of a case statement.
The second version is much more elegant , and doesn't require having to type comparison clauses.
Wherever there's an existing function/method to save time and code like this, use it. :)