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

GAD Slips

Slip 1
Task 1 Write a program on Arithmetic Operations using MsgBox().
Ans)
Module Module1
Sub Main()
Dim num1 As Integer = 10
Dim num2 As Integer = 5

Dim sum As Integer = num1 + num2


Dim difference As Integer = num1 - num2
Dim product As Integer = num1 * num2
Dim quotient As Double = num1 / num2

MsgBox("Sum: " & sum)


MsgBox("Difference: " & difference)
MsgBox("Product: " & product)
MsgBox("Quotient: " & quotient)

Console.ReadLine()
End Sub
End Module

Task 2 Oral
Slip 2
Task 1 Write a program using InputBox(), MsgBox() and perform various Arithmetic
Operations
Ans)
Module Module1
Sub Main()
Dim num1 As Integer
Dim num2 As Integer

num1 = InputBox("Enter the first number:")


num2 = InputBox("Enter the second number:")

Dim sum As Integer = num1 + num2


Dim difference As Integer = num1 - num2
Dim product As Integer = num1 * num2
Dim quotient As Double = num1 / num2

MsgBox("Sum: " & sum)


MsgBox("Difference: " & difference)
MsgBox("Product: " & product)
MsgBox("Quotient: " & quotient)

Console.ReadLine()
End Sub
End Module
Task 2 Oral
Slip 3
Task 1 Write a program using if-else statement to find the number is even or odd.
Ans)
Module Module1
Sub Main()
Dim number As Integer
Console.Write("Enter a number: ")
number = Console.ReadLine()

If number Mod 2 = 0 Then


Console.WriteLine("The number is even.")
Else
Console.WriteLine("The number is odd.")
End If

Console.ReadLine()
End Sub
End Module
Task 2 Oral
Slip 4
Task 1 Write a program using Select Case statements to count the number of Vowels in
A to Z alphabets.
Ans)
Module Module1
Sub Main()
Dim alphabet As String = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Dim vowelsCount As Integer = 0

For Each letter As Char In alphabet


Select Case Char.ToUpper(letter)
Case "A", "E", "I", "O", "U"
vowelsCount += 1
End Select
Next

Console.WriteLine("Number of vowels in the alphabet: " & vowelsCount)

Console.ReadLine()
End Sub
End Module
Task 2 Oral
Slip 5
Task 1 Write a program for performing arithmetic operations using select case
Statement.
Ans)
Module Module1
Sub Main()
Dim num1, num2 As Integer
Dim operation As String

Console.Write("Enter the first number: ")


num1 = Console.ReadLine()
Console.Write("Enter the second number: ")
num2 = Console.ReadLine()
Console.Write("Enter the operation (add, subtract, multiply, divide): ")
operation = Console.ReadLine().ToLower()

Select Case operation


Case "add"
Console.WriteLine("Result: " & (num1 + num2))
Case "subtract"
Console.WriteLine("Result: " & (num1 - num2))
Case "multiply"
Console.WriteLine("Result: " & (num1 * num2))
Case "divide"
If num2 = 0 Then
Console.WriteLine("Error: Division by zero")
Else
Console.WriteLine("Result: " & (num1 / num2))
End If
Case Else
Console.WriteLine("Error: Invalid operation")
End Select

Console.ReadLine()
End Sub
End Module

Task 2 Oral
Slip 6
Task 1 Write a program using the While statement to print the prime numbers
between 1 to 100.
Ans)
Module Module1
Sub Main()
Dim number As Integer = 2

Console.WriteLine("Prime numbers between 1 and 100:")


While number <= 100
Dim divisor As Integer = 2
Dim isPrime As Boolean = True

While divisor <= Math.Sqrt(number)


If number Mod divisor = 0 Then
isPrime = False
Exit While
End If
divisor += 1
End While

If isPrime Then
Console.WriteLine(number)
End If

number += 1
End While

Console.ReadLine()
End Sub
End Module
Task 2 Oral
Slip 7
Task 1 Write a program using While statement to print even-odd numbers between 1
to 50
Ans)
Module Module1
Sub Main()
Dim number As Integer = 1

Console.WriteLine("Even and Odd numbers between 1 and 50:")


While number <= 50
If number Mod 2 = 0 Then
Console.WriteLine("Even: " & number)
Else
Console.WriteLine("Odd: " & number)
End If
number += 1
End While

Console.ReadLine()
End Sub
End Module
Task 2 Oral
Slip 8
Task 1 Write a program to change the background color of the form when the user
clicks on different buttons.
Ans)
Imports System.Windows.Forms

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Me.BackColor = Color.Red
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
Me.BackColor = Color.Blue
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles


Button3.Click
Me.BackColor = Color.Green
End Sub
End Class

Output:

Task 2 Oral
Slip 9
Task 1 Write the program using Radio Button to change the bulb state ON/OFF.
Ans)
Public Class Form1
Private Sub RadioButton1_CheckedChanged(sender As Object, e As
EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked Then
PictureBox2.Show()
PictureBox1.Hide()
End If
End Sub

Private Sub RadioButton2_CheckedChanged(sender As Object, e As


EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked Then
PictureBox1.Show()
PictureBox2.Hide()
End If
End Sub
End Class

Output:
Task 2 Oral
Slip 10
Task 1 Write a program using Radio Button to display Gender.
Ans)
Public Class Form1
Private Sub RadioButton1_CheckedChanged(sender As Object, e As
EventArgs) Handles RadioButton1.CheckedChanged
If RadioButton1.Checked Then
Label2.Text = "Gender entered is male"
End If
End Sub

Private Sub RadioButton2_CheckedChanged(sender As Object, e As


EventArgs) Handles RadioButton2.CheckedChanged
If RadioButton2.Checked Then
Label2.Text = "Gender entered is Female"
End If
End Sub
End Class

Output:

Task 2 Oral
Slip 11
Task 1 Write a program to select multiple subjects for single semester (Using Combo
Box).
Ans)
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
ComboBox1.Items.Add("Mathematics")
ComboBox1.Items.Add("Physics")
ComboBox1.Items.Add("Chemistry")
ComboBox1.Items.Add("Biology")
ComboBox1.Items.Add("Computer Science")
End Sub

Private Sub ComboBox1_SelectedIndexChanged(sender As Object, e As


EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedIndex <> -1 Then
MsgBox(ComboBox1.SelectedItem.ToString())
End If
End Sub
End Class

Output:

Task 2 Oral
Slip 12
Task 1 Write a program using picture box control to load an image at run time.
Ans)
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles
MyBase.Load

Dim imagePath As String = "C:\Users\Dell\Pictures\Bulb_on.jpg"

If System.IO.File.Exists(imagePath) Then
PictureBox1.Image = Image.FromFile(imagePath)
Else
MsgBox("Image file not found!")
End If
End Sub
End Class

Output:

Task 2 Oral
Slip 13
Task 1 Write a program to display the traffic signal using timer control.
Ans)
Public Class Form1
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles
Timer1.Tick
If PictureBox1.Visible Then
PictureBox1.Visible = False
PictureBox2.Visible = True
PictureBox3.Visible = False
ElseIf PictureBox2.Visible Then
PictureBox1.Visible = False
PictureBox2.Visible = False
PictureBox3.Visible = True
ElseIf PictureBox3.Visible Then
PictureBox1.Visible = True
PictureBox2.Visible = False
PictureBox3.Visible = False
End If
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles


MyBase.Load
Timer1.Enabled = True
Timer1.Interval = 1600 ' Adjust the interval as needed
PictureBox1.Visible = True
PictureBox2.Visible = False
PictureBox3.Visible = False
End Sub
End Class

Task 2 Oral
Slip 14
Task 1 Write a program using Error Provider for username and password
authentication.
Ans)
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
If TextBox1.Text = "" Then
ErrorProvider1.SetError(TextBox1, "Please Enter Your Name")
Else
ErrorProvider1.SetError(TextBox1, "")
End If
If TextBox2.Text = "" Then
ErrorProvider1.SetError(TextBox2, "Please Enter Your Password")
Else
ErrorProvider1.SetError(TextBox2, "")
End If
End Sub
End Class

Output:

Task 2 Oral
Slip 15
Task 1 Write a program to identify maximum number using parameterized Function.
Ans)
Module Module1
Sub Main()
Console.WriteLine("Enter three numbers:")
Dim num1 As Integer = Console.ReadLine()
Dim num2 As Integer = Console.ReadLine()
Dim num3 As Integer = Console.ReadLine()

Dim maxNumber As Integer = FindMax(num1, num2, num3)

Console.WriteLine("The greatest number is: " & maxNumber)


Console.ReadLine()
End Sub

Function FindMax(ByVal num1 As Integer, ByVal num2 As Integer, ByVal


num3 As Integer) As Integer
Dim max As Integer = num1
If num2 > max Then max = num2
If num3 > max Then max = num3
Return max
End Function
End Module

Task 2 Oral
Slip 16
Task 1 Write a Program using Error Provider control to validate the Mobile Number
and Email-Id in GUI application.
Ans)
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim number As New Regex("\d{10}")
If number.IsMatch(TextBox1.Text) Then
ErrorProvider1.SetError(TextBox1, "")
MsgBox("Valid Phone Number")
Else
ErrorProvider1.SetError(TextBox1, "Invalid Phone Number")
End If
Dim regex As Regex = New Regex("^([\w-\.]+)@((\[[0 9]{1,3}\.[0
9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"
)
Dim isValid As Boolean = regex.IsMatch(TextBox2.Text.Trim)
If Not isValid Then
ErrorProvider1.SetError(TextBox2, "Invalid E-mail ID")
Else
ErrorProvider1.SetError(TextBox2, "")
MsgBox("Valid E-Mail ID")
End If
End Sub
End Class

Output:

Task 2 Oral
Slip 17
Task 1 Write a Program on windows application for employee details using overriding
method.
Ans)
Module Module1
Sub Main()
Dim obj As New EmpInfo
obj.name = "John Doe"
obj.address = "123 Main St"
obj.EmpId = 101
obj.sallary = 50000
obj.JoinDate = Date.Now
obj.ShowInfo()
Console.ReadLine()
End Sub
End Module

Public Class EmpPersonalDetails


Public name As String
Public address As String

Public Overridable Function ShowInfo() As String


Console.WriteLine("Employee Name: " & name)
Console.WriteLine("Employee Address: " & address)
Return ""
End Function
End Class
Public Class EmpInfo
Inherits EmpPersonalDetails
Public EmpId As Integer
Public sallary As Integer
Public JoinDate As Date

Public Overrides Function ShowInfo() As String


MyBase.ShowInfo()
Console.WriteLine("Employee ID: " & EmpId)
Console.WriteLine("Employee Salary: " & sallary)
Console.WriteLine("Employee Joining Date: " & JoinDate)
Return ""
End Function
End Class

Task 2 Oral
Slip 18
Task 1 Write a Program to identify Volume of Box Class With three data members as
length, breadth and height (Using Class and Object).
Ans)
Module Module1
Sub Main()
Dim myBox As New Box()
myBox.Length = 5
myBox.Breadth = 3
myBox.Height = 2
Console.WriteLine("Volume of the box: " & myBox.CalculateVolume())
Console.ReadLine()
End Sub

Public Class Box


Public Length As Double
Public Breadth As Double
Public Height As Double

Public Function CalculateVolume() As Double


Return Length * Breadth * Height
End Function
End Class
End Module
Task 2 Oral
Slip 19
Task 1 Write a program to Calculate area of Circle using Parameterized constructor.
Ans)
Module Module1
Sub Main()
Dim circle As New Circle(5)
Console.WriteLine("Area of the circle: " & circle.CalculateArea())
Console.ReadLine()
End Sub

Public Class Circle


Private Radius As Double

Public Sub New(ByVal radiusValue As Double)


Radius = radiusValue
End Sub

Public Function CalculateArea() As Double


Return Math.PI * Radius * Radius
End Function
End Class
End Module

Task 2 Oral
Slip 20
Task 1 Write a program for inheritance where Student is Child class and Faculty is
Parent Class (Take appropriate variables in Base and Derived Class).
Ans)
Module Module1
Sub Main()
Dim student As New Student("John Doe", "CS", 20)
Dim faculty As New Faculty("Dr. Smith", "Mathematics", 40)

Console.WriteLine("Student Name: " & student.Name)


Console.WriteLine("Student Department: " & student.Department)
Console.WriteLine("Student Age: " & student.Age)

Console.WriteLine(vbCrLf & "Faculty Name: " & faculty.Name)


Console.WriteLine("Faculty Department: " & faculty.Department)
Console.WriteLine("Faculty Age: " & faculty.Age)

Console.ReadLine()
End Sub

Public Class Faculty


Public Name As String
Public Department As String
Public Age As Integer

Public Sub New(ByVal nameValue As String, ByVal departmentValue As


String, ByVal ageValue As Integer)
Name = nameValue
Department = departmentValue
Age = ageValue
End Sub
End Class
Public Class Student
Inherits Faculty
Public Sub New(ByVal nameValue As String, ByVal departmentValue As
String, ByVal ageValue As Integer)
MyBase.New(nameValue, departmentValue, ageValue)
End Sub
End Class
End Module

Task 2 Oral
Slip 21
Task 1 Write a program for Student Registration using Exception Handling .
Ans)
Module Module1
Sub Main()
Try
Console.WriteLine("Enter Student Name:")
Dim name As String = Console.ReadLine()

Console.WriteLine("Enter Student Age:")


Dim age As Integer = Integer.Parse(Console.ReadLine())

Console.WriteLine("Enter Student Email:")


Dim email As String = Console.ReadLine()

Dim student As New Student(name, age, email)

Console.WriteLine("Student Registration Successful!")


Catch ex As Exception
Console.WriteLine("An error occurred: " & ex.Message)
End Try

Console.ReadLine()
End Sub

Public Class Student


Public Name As String
Public Age As Integer
Public Email As String

Public Sub New(ByVal name As String, ByVal age As Integer, ByVal email As
String)
If age < 18 Or age > 100 Then
Throw New ArgumentException("Age must be between 18 and 100.")
End If

If Not email.Contains("@") Or Not email.Contains(".") Then


Throw New ArgumentException("Invalid email format.")
End If

Me.Name = name
Me.Age = age
Me.Email = email
End Sub
End Class
End Module
Task 2 Oral
Slip 22
Task 1 Write a program for Recursion using a function.
Ans)
Module Module1
Sub Main()
Console.WriteLine("Enter a number:")
Dim number As Integer = Console.ReadLine()
Console.WriteLine("Factorial : " & Factorial(number))
Console.ReadLine()
End Sub

Function Factorial(ByVal n As Integer) As Integer


If n = 0 Then
Return 1
Else
Return n * Factorial(n - 1)
End If
End Function
End Module

Task 2 Oral
Slip 23
Task 1 Write a program to perform method Overloading as addition of two and three
numbers.
Ans)
Module Module1
Sub Main()
Dim result1 As Integer = Add(5, 10)
Console.WriteLine("Addition of two numbers: " & result1)

Dim result2 As Integer = Add(5, 10, 15)


Console.WriteLine("Addition of three numbers: " & result2)

Console.ReadLine()
End Sub

Function Add(ByVal num1 As Integer, ByVal num2 As Integer) As Integer


Return num1 + num2
End Function
Function Add(ByVal num1 As Integer, ByVal num2 As Integer, ByVal num3 As
Integer) As Integer
Return num1 + num2 + num3
End Function
End Module
Task 2 Oral
Slip 24
Task 1 Write a program to perform the Date Validation using Errorprovider control.
Ans)
Imports System.Text.RegularExpressions

Public Class Form1


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
Dim regex As Regex = New Regex("(((0|1)[0-9]|2[0-9]|3[0-1])\/(0[1-
9]|1[0-2])\/((19|20)\d\d))$")
Dim isValidFormat As Boolean = regex.IsMatch(TextBox1.Text.Trim)

If Not isValidFormat Then


ErrorProvider1.SetError(TextBox1, "Invalid Format")
Else
MsgBox("Valid Format")
ErrorProvider1.SetError(TextBox1, "")
End If
End Sub
End Class

Task 2 Oral
Slip 25
Task 1 Write a program using for-next loop statements to find the Armstrong numbers
between 1 to 500.
Ans)
Module Module1
Sub Main()
Dim number, digit, sum As Integer
Console.WriteLine("Armstrong Numbers Between 1 to 500:")
For number = 1 To 500
Dim tempNumber As Integer = number
sum = 0
While tempNumber > 0
digit = tempNumber Mod 10
sum += digit * digit * digit
tempNumber \= 10
End While
If number = sum Then
Console.WriteLine(number)
End If
Next
Console.ReadLine()
End Sub
End Module
Task 2 Oral
Slip 26
Task 1 Write a program for database connectivity and perform Insert, Update
commands for data in the access database.
Ans)

Task 2 Oral

You might also like