O'Reilly logo

Visual Basic® .NET by Example by Bob Donald, Gabriel Oancea

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The If Statement

The If statements is one of the most common Visual Basic statements. It allows you to execute one or more statements only when a specific condition is met. This condition is a Boolean expression that will evaluate to True or False. Let's look at an example:

Sub Main()
   Console.Out.WriteLine("Enter a value for i and press <ENTER>: ")
   Dim i As Integer
   i = CInt(Console.In.ReadLine())

   Console.Out.WriteLine("Enter a value for j and press <ENTER>: ")
   Dim j As Integer
   j = CInt(Console.In.ReadLine())

   If i < j Then
      Console.Out.WriteLine("i is less than j")
   End If

   Console.Out.WriteLine("Press the <Enter> key to end the program")
   Console.In.ReadLine()
End Sub

These example declare two Integer variables i and j and gets some values for ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required