VB.NET Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
Visual Basic Tutorial
Introduction
Installation
Creating Project
Saving a Project
Compile, Run a Project
Open an Existing Project
VB IDE
Forms
VB Datatypes
Constants
Variables
User Defined Datatypes
VB Control Structure
VB Loops
Operators
VB Controls
Dialog Controls
Console Programming
VB Objects,Classes
VB Arrays
Math Functions
String Functions
Type Conversion Functions
Date Time Functions
Databases in VB.net
Enumeration
File Handling
Debugging
Debugging Tools
Exception Handling
Samples
Feedback
 




Nested If Then Else Statement in VB.NET

Tutorials Vbnet

Topic

How to use nested if then else statement in VB.NET?



Explanation
Nested If Then Else Statement

     Nested If..Then..Else statement is used to check multiple conditions using if then else statements nested inside one another.

Syntax:
If [Condition] Then
   If [Condition] Then
     [Statements]
   Else
     [Statements]
Else
   [Statements]

In the above syntax when the Condition of the first if then else is true, the second if then else is executed to check another two conditions. If false the statements under the Else part of the first statement is executed.

Example:
 Private Sub Button1_Click(ByVal sender As System.Object,
      ByVal e As System.EventArgs) Handles Button1.Click
    If Val(TextBox1.Text) >= 40 Then
       If Val(TextBox1.Text) >= 60 Then
          MsgBox("You have FIRST Class")
       Else
          MsgBox("You have SECOND Class")
       End If
    Else
       MsgBox("Check your Average marks entered")
    End If
 End Sub
Description:

In the above nested if then else statement example first the average mark is checked if it is more than 40, if true the second if then else control is used check for first or second class. If the first condition is false the statements under the else part is executed.







Other Links

web hosting