Simplified SWITCH Statement

Just a quick one today that might help you clean up some code somewhere.

I have a process where we are importing some glossary terms for 5 different languages. All of the logic is identical except for the LanguageID. So I have a simple FOR loop that runs 5 times, the problem is that the Language ID for each loop needs to be different, and there is no logical connection between which pass of the loop and the LanguageID number. So I had code similar to this:

2014-11-13_1002

Nothing wrong with that code, but that big long SWITCH statement was distracting to me and made it harder to follow the logic at a glance. I knew there was a cleaner way to do it, so after a few searches in the online help, I found the syntax for a “Simplified SWITCH Statement”. If the comparison value is a series of consecutive integers, in my case 1 – 5, you can use a simplified version of the SWITCH statement like this:

2014-11-13_1014

Nothing earth shattering there by any means, but it does let you see the important portion of the the logic, the import code, without being distracted by 12 lines of a SWITCH statement

Now, back to your regular schedule program….

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s