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

Chapter 6 - Using Decision Structures - Part 1

By , About.com Guide

6 of 6

Entering the If-Then-Else Code

So ... following the diagram on the previous page ... you could code an If-Then-Else as ...

~~~~~~~~~~~~~~~~~~~~~~~~~
If condition1 Then
  statement1
  statement2
End If
~~~~~~~~~~~~~~~~~~~~~~~~~

or

~~~~~~~~~~~~~~~~~~~~~~~~~
If condition3 Then
  statement4
ElseIf condition5 Then
  statement6
End If
~~~~~~~~~~~~~~~~~~~~~~~~~

... in addition to many other possibilities. The Intellisense feature in Visual Studio .NET helps a lot too by filling in part of the statements for you. These diagrams aren't as foolproof as the BNF (Backus-Naur Form) that was explained in the previous chapter. For example, the diagram would seem to suggest that ...

~~~~~~~~~~~~~~~~~~~~~~~~~
If condition
End If
~~~~~~~~~~~~~~~~~~~~~~~~~

... is a legal structure. But Visual Studio fills in Thenfor you automatically. Another point is that you are free to code completely meaningless statements, such as ...

~~~~~~~~~~~~~~~~~~~~~~~~~
If condition Then
End If
~~~~~~~~~~~~~~~~~~~~~~~~~

VB.NET will compile and run them just like statements that actually do something!

Explore Visual Basic
By Category
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. 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 1

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

All rights reserved.