If...Then...Else statement

Usage

The following code tests several conditions and displays the appropriate message.

If Age < 16 Then
   ' This code executes if Age is less than 16
   Msgbox "You are not old enough for a license"
ElseIf Age > 100 Then
   ' This code executes if Age is greater than 100
   Msgbox "You are too old to drive!"
Else
   ' This code executes if Age does not match any of the other conditions
   Msgbox "You can be tested for a license"
End If

You might also like...

Comments

About the author

James Crowley

James Crowley United Kingdom

James first started this website when learning Visual Basic back in 1999 whilst studying his GCSEs. The site grew steadily over the years while being run as a hobby - to a regular monthly audien...

Interested in writing for us? Find out more.

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“The first 90% of the code accounts for the first 90% of the development time. The remaining 10% of the code accounts for the other 90% of the development time.” - Tom Cargill