You are here:About>Computing & Technology>Visual Basic> Learn VB.NET> Using Decision Structures - Part 2
About.comVisual Basic
Newsletters & RSSEmail to a friendSubmit to Digg

Chapter 6 - Using Decision Structures - Part 2

From Dan Mabbutt,
Your Guide to Visual Basic.
FREE Newsletter. Sign Up Now!

If-Then-Else compared with Select Case

The Select Case structure looks like this illustration in the Microsoft documentation. The second major topic of this lesson is to show you how Select Case and If-Then-Else can actually be used for exactly the same programming problem sometimes. It's up to you, as a programmer, to decide which one works best.

The example that we'll use is the same one in the book.

Here's the code in the book:

~~~~~~~~~~~~~~~~~~~~~~~~~
Dim AdjustedIncome, TaxDue As Double

If AdjustedIncome <= 27050 Then ' 15% tax bracket
  TaxDue = AdjustedIncome * 0.15
ElseIf AdjustedIncome <= 65550 Then ' 28% tax bracket
  TaxDue = 4057.5 + ((AdjustedIncome - 27050) * 0.28)
ElseIf AdjustedIncome <= 136750 Then ' 31% tax bracket
  TaxDue = 4057.5 + ((AdjustedIncome - 65550) * 0.31)
ElseIf AdjustedIncome <= 297350 Then ' 36% tax bracket
  TaxDue = 4057.5 + ((AdjustedIncome - 136750) * 0.36)
Else ' 39.6% tax bracket
  TaxDue = 4057.5 + ((AdjustedIncome - 297350) * 0.396)
End If
~~~~~~~~~~~~~~~~~~~~~~~~~

  1. If-Then-Else compared with Select Case
  2. The Select Case Structure
  3. Bonus Page: The IIF Function is another decision structure you can use

Previous | Next >>

 All Topics | Email Article | | |
Advertising Info | News & Events | Work at About | SiteMap | Reprints | HelpOur 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.