| You are here: | About>Computing & Technology>Visual Basic> Learn VB.NET> If-Then-Else compared with Select Case |
![]() | Visual Basic |
If-Then-Else compared with Select CaseYou can often use one in place of the other ...This article is extracted from Lesson 7 of the About Visual Basic "Complete Course" for VB.NET. Sign up for the entire course at ... this signup page. In this lesson, we show you how Select Case and If-Then-Else can actually be used for exactly the same programming problem. It's up to you, as a programmer, to decide which one works best. Click Here to see an example of the basic If-Then-Else syntax in the Microsoft documentation. Click the "Back" button in your browser to return. We will use code taken from the text used for the "Complete Course", Microsoft Visual Basic .NET Step by Step. Although this code is left justified here, copy and paste it into Visual Studio .NET and it will be formatted correctly.
Whenever you have a series of decisions like this, a Select Case structure ought to be considered. Here's the same code using a Select Case Structure. Again, copy and paste this into the VB.NET editor in Visual Studio .NET for a correctly formatted version.
If you initialize AdjustedIncome to say, $1,000,000 (that is, a small, insignificant fraction of what Bill Gates makes in a year), you will find that you get exactly the same answer with either code. Use MsgBox or Debug.Write to see the answer. (If you use Debug.Write, make sure the Output window is displayed.) So ... Assignment: Which One Should You Use? I'll give you MY answer in the "Complete Course" for VB.NET. Sign up for the entire course at ... this signup page. |
Las Vegas on a BudgetFind a BargainHotel DealsCheap EatsFree AttractionsEntertainment for Less |
All Topics | Email Article | | | ![]() |
| Advertising Info | News & Events | Work at About | SiteMap | Reprints | Help | Our Story | Be a Guide |
| User Agreement | Ethics Policy | Patent Info. | Privacy Policy | ©2008 About, Inc., A part of The New York Times Company. All rights reserved. |


