Practical No 04 Gad 22034 1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

Practical No. 4: Implement a program for If-else control structures in VB.NET.

Practical No: 04

VIII. Resources required (Additional)


- If any web reference is required.

X. Resources required (Actual)


(1) https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/statements/if-then-
else-statement
(2) https://www.tutorialspoint.com/vb.net/vb.net_if_else_statements.htm

XI. Program Code:


Write a program using if-else statement –
 Module Module1
Sub Main()
Dim n As Integer
Console.WriteLine("Enter a Number")
n = Console.ReadLine()
If (n > 0) Then
Console.WriteLine("Number is Positive")
Else
Console.WriteLine("Number is Negative")
End If
Console.ReadLine()
End Sub
End Module

Results (Output of the Program)


Enter a number:
9
Number is Positive

XIII. Practical Related Questions


1. Write program for finding greatest among three numbers –
 Module Module1
Sub Main()
Dim a, b, c As Integer
Console.Write("Enter the values of a, b and c:")
a = Val(Console.ReadLine())
b = Val(Console.ReadLine())
c = Val(Console.ReadLine())
If (a > b) Then
If (a > c) Then
Console.WriteLine("Greatest Number is:" & a)
Else
Console.WriteLine("Greatest Number is:" & c)

End If
Else
If (b > c) Then

GUI Application Development using VB.Net (22034) Page 1


Practical No. 4: Implement a program for If-else control structures in VB.NET.

Console.WriteLine("Greatest Number is:" & b)


Else
Console.WriteLine("Greatest Number is:" & c)
End If
End If
Console.ReadLine()
End Sub
End Module
Results (Output of the Program)
Enter the values of a, b and c:23
65
12
Greatest Number is:65

2. Implement the program using if-else statement to find the number is even or odd –
 Module Module1
Dim i As Integer

Sub Main()
Console.WriteLine("Enter Number")
i = Console.ReadLine()
If ((i Mod 2) = 0) Then
Console.WriteLine("Number is Even")
Else
Console.WriteLine("Number is Odd")
End If
Console.ReadLine()
End Sub
End Module

Results (Output of the Program)


Enter a number:
9
Number is Odd

XIV. Exercise
1. Write the program using if-else statement for following output.
Result Percentage Criteria
Fail perc < 40
Second Class perc > 40 AND perc < 60
First Class perc > 60 AND perc < 75
Distinction perc > 75

 Module Module1

Sub Main()
Dim perc As Integer
Console.Write("Enter Percentage:")
perc = Val(Console.ReadLine())
GUI Application Development using VB.Net (22034) Page 2
Practical No. 4: Implement a program for If-else control structures in VB.NET.

If (perc < 40) Then


Console.WriteLine("Fail")
ElseIf ((perc > 40) And (perc < 60)) Then
Console.WriteLine("Pass Class")
ElseIf ((perc >= 60) And (perc < 75)) Then
Console.WriteLine("First Class")
ElseIf (perc >= 75) Then
Console.WriteLine("Distinction")
End If
Console.ReadLine()
End Sub

End Module

Results (Output of the Program)


Enter Percentage:85
Distinction

2. Write output of following code.


 Module Module1

Sub Main()
Dim i As Integer
i=4
Dim a As Double
a = -1.0

If (i > 0) Then
If (a > 0) Then
Console.WriteLine("Here I am !!!!")
Else
Console.WriteLine("No here I am ??")
Console.WriteLine("Actually here I am ??")
End If
End If

Console.ReadKey()
End Sub

End Module

Results (Output of the Program)


No here I am ??
Actually here I am ??

GUI Application Development using VB.Net (22034) Page 3

You might also like