Home »
VB.Net »
VB.Net Programs
VB.Net program to demonstrate the nested 'select case'
By Nidhi Last Updated : November 13, 2024
Nested 'select case' in VB.Net
Here, we will define select case inside the case, which is known as nested 'select case'.
Program/Source Code:
The source code to demonstrate the nested "select case" is given below. The given program is compiled and executed successfully.
VB.Net code to demonstrate the examples of nested 'select case'
'VB.Net program to demonstrate the
'nested "select case"
Module Module1
Sub Main()
Dim choice1 As Integer = 2
Dim choice2 As Single = 2.2
Select Case choice1
Case 1
Select Case choice2
Case 1.1
Console.WriteLine("Option 1.1")
Case 1.2
Console.WriteLine("Option 1.2")
Case 1.3
Console.WriteLine("Option 1.3")
End Select
Case 2
Select Case choice2
Case 2.1
Console.WriteLine("Option 2.1")
Case 2.2
Console.WriteLine("Option 2.2")
Case 2.3
Console.WriteLine("Option 2.3")
End Select
Case 3
Select Case choice2
Case 3.1
Console.WriteLine("Option 3.1")
Case 3.2
Console.WriteLine("Option 3.2")
Case 2.3
Console.WriteLine("Option 3.3")
End Select
Case Else
Console.WriteLine("Invalid choice")
End Select
End Sub
End Module
Output:
Option 2.2
Press any key to continue . . .
Explanation:
In the above program, we created a module Module1 that contains a Main() method. In the Main() method, we created two variables choice1 and choice2 that are initialized with 2 and 2.2 respectively.
In the above program, we defined "select case" inside the "select case", which is known as a nested select case. Here, "case 2.2" will be executed and then print the appropriate message on the console screen.
VB.Net Basic Programs »