O'Reilly logo

Special Edition Using Microsoft® Visual Basic® .NET by Jeff Spotts, Brian Siler

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

Understanding If Statements

For many decisions, you may want to execute a statement (or group of statements) only if a particular condition is True. Two forms of the If statement handle True conditions: the single-line If statement and the multiple-line If statement. Each uses the If statement to check a condition. If the condition is True, the program runs the commands associated with the If statement. For example, the following two If statements perform the same function:

'Single-Line IF 
If x > 5 then x = 0 

'Multiple-Line IF 
If x > 5 Then 
    x = 0 
End If 

In the code sample, the condition is the value of the variable x being greater than 5. If this condition is True the statement x=0 will be executed. If the condition is False (in the preceding ...

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