1. Home
  2. Computing & Technology
  3. Visual Basic

Chapter 6 - Using Decision Structures - Part 2

By , About.com Guide

1 of 3

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
~~~~~~~~~~~~~~~~~~~~~~~~~

Explore Visual Basic
By Category
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Learn VB.NET
  5. Using Decision Structures - Part 2

©2010 About.com, a part of The New York Times Company.

All rights reserved.