Program 1: text box and combo box(output ok)
Coding:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs)
Handles Button1.Click
ComboBox1.Items.Add(TextBox1.Text)
TextBox1.Clear()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs)
Handles Button2.Click
ComboBox1.Items.Clear()
End Sub
End Class
Design Window:
Output
Program 2: tree view control (output ok)
Coding:
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs)
Handles Button1.Click
Dim node As String
node = InputBox("Enter Node name ") ' Corrected variable
usage
If TreeView1.SelectedNode Is Nothing Then
TreeView1.Nodes.Add(New TreeNode(node)) ' Fixed
incorrect Add method usage
Else
TreeView1.SelectedNode.Nodes.Add(New TreeNode(node))
End If
End Sub
Private Sub TreeView1_AfterSelect(sender As Object, e As
TreeViewEventArgs) Handles TreeView1.AfterSelect
Me.Text = "RdLab"
Button1.Text = "Add New Node"
End Sub
End Class
Design Window:
PROGRAM 3: EXCEPTION (output ok)
Coding:
Imports System
Class CustomException
Inherits ApplicationException
Public Sub New(Message As String)
MyBase.New(Message)
End Sub
End Class
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs)
Handles Button1.Click
Try
Dim age As Integer = Integer.Parse(TextBox1.Text) ' Fixed
TextBox reference
If age < 0 Then
Throw New CustomException("Age cannot be Negative.")
End If
MessageBox.Show("Age Entered: " & age) ' Improved
readability
Catch ex As CustomException
MessageBox.Show(ex.Message) ' Handling custom exception
Catch ex As FormatException
MessageBox.Show("Please enter a valid number.") ' Handling
invalid input format
Catch ex As Exception
MessageBox.Show("An error occurred: " & ex.Message) '
Generic error handler
End Try
End Sub
End Class
Design Window:
Output
Program 4: employee details (output ok)
Coding:
Imports System.Reflection
Public Class Form1
' Define Employee class
Public Class Employee
' Properties
Public Property Name As String
Public Property Age As Integer
Public Property Department As String
Public Property Position As String
Public Property Salary As Integer
' Constructor
Public Sub New(name As String, age As Integer, department As
String, position As String, salary As Integer)
Me.Name = name
Me.Age = age
Me.Department = department
Me.Position = position
Me.Salary = salary
End Sub
End Class
' Button Click Event
Private Sub Button1_Click(sender As Object, e As EventArgs)
Handles Button1.Click
Try
' Getting input from TextBoxes
Dim name As String = TextBox1.Text
Dim age As Integer = Integer.Parse(TextBox2.Text)
Dim department As String = TextBox3.Text
Dim position As String = TextBox4.Text
Dim salary As Integer = Integer.Parse(TextBox5.Text) ' Proper
conversion
' Creating Employee object
Dim employee As New Employee(name, age, department,
position, salary)
' Displaying Employee Details
MessageBox.Show($"Name: {employee.Name}{vbCrLf}" &
$"Age: {employee.Age}{vbCrLf}" &
$"Department: {employee.Department}{vbCrLf}" &
$"Position: {employee.Position}{vbCrLf}" &
$"Salary: {employee.Salary}", "Employee Details")
MessageBox.Show("Employee details successfully entered.",
"Success")
Catch ex As FormatException
MessageBox.Show("Please enter valid numeric values for
Age and Salary.", "Input Error")
Catch ex As Exception
MessageBox.Show($"An error occurred: {ex.Message}",
"Error")
End Try
End Sub
End Class
Design Window:
Output:
Program 5: click, mouse down, key down, form load(output ok)
Coding:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs)
Handles MyBase.Load
MessageBox.Show("Form Loaded")
End Sub
Private Sub Form1_Click(sender As Object, e As EventArgs)
Handles MyBase.Click
MessageBox.Show("Form Clicked")
End Sub
Private Sub Form1_MouseDown(sender As Object, e As
MouseEventArgs) Handles MyBase.MouseDown
If e.Button = MouseButtons.Left Then
MessageBox.Show("Left Mouse Button Pressed")
ElseIf e.Button = MouseButtons.Right Then
MessageBox.Show("Right Mouse Button Pressed")
End If
End Sub
Private Sub Form1_KeyDown(sender As Object, e As
KeyEventArgs) Handles MyBase.KeyDown
MessageBox.Show("Key Pressed: " & e.KeyCode.ToString())
End Sub
End Class
Design Window:
Output:
Program 6 : file menu with menu items (output ok)
Coding:
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs)
Handles MyBase.Load
InitializeMenus()
End Sub
Private Sub InitializeMenus()
' File Menu
Dim fileMenu As ToolStripMenuItem = CreateMenuItem("File")
fileMenu.DropDownItems.Add(CreateMenuItem("New",
AddressOf NewFile_Click))
fileMenu.DropDownItems.Add(CreateMenuItem("Open",
AddressOf OpenFile_Click))
fileMenu.DropDownItems.Add(CreateMenuItem("Save",
AddressOf SaveFile_Click))
fileMenu.DropDownItems.Add(CreateMenuItem("Print",
AddressOf PrintFile_Click))
fileMenu.DropDownItems.Add(CreateMenuItem("Exit",
AddressOf ExitApplication_Click))
' Edit Menu
Dim editMenu As ToolStripMenuItem =
CreateMenuItem("Edit")
editMenu.DropDownItems.Add(CreateMenuItem("Cut",
AddressOf Cut_Click))
editMenu.DropDownItems.Add(CreateMenuItem("Copy",
AddressOf Copy_Click))
editMenu.DropDownItems.Add(CreateMenuItem("Paste",
AddressOf Paste_Click))
editMenu.DropDownItems.Add(CreateMenuItem("Find",
AddressOf Find_Click))
editMenu.DropDownItems.Add(CreateMenuItem("Undo",
AddressOf Undo_Click))
' Create and assign MenuStrip
Dim menuStrip As New MenuStrip()
menuStrip.Items.Add(fileMenu)
menuStrip.Items.Add(editMenu)
' Set MenuStrip to the form
Me.Controls.Add(menuStrip)
Me.MainMenuStrip = menuStrip ' Ensuring proper MenuStrip
recognition
End Sub
Private Function CreateMenuItem(text As String, Optional
clickHandler As EventHandler = Nothing) As ToolStripMenuItem
Dim menuItem As New ToolStripMenuItem(text)
If clickHandler IsNot Nothing Then
AddHandler menuItem.Click, clickHandler
End If
Return menuItem
End Function
' File Menu Handlers
Private Sub NewFile_Click(sender As Object, e As EventArgs)
MessageBox.Show("New File")
End Sub
Private Sub OpenFile_Click(sender As Object, e As EventArgs)
MessageBox.Show("Open File")
End Sub
Private Sub SaveFile_Click(sender As Object, e As EventArgs)
MessageBox.Show("Save File")
End Sub
Private Sub PrintFile_Click(sender As Object, e As EventArgs)
MessageBox.Show("Print File")
End Sub
Private Sub ExitApplication_Click(sender As Object, e As
EventArgs)
Me.Close()
End Sub
' Edit Menu Handlers
Private Sub Cut_Click(sender As Object, e As EventArgs)
MessageBox.Show("Cut")
End Sub
Private Sub Copy_Click(sender As Object, e As EventArgs)
MessageBox.Show("Copy")
End Sub
Private Sub Paste_Click(sender As Object, e As EventArgs)
MessageBox.Show("Paste")
End Sub
Private Sub Find_Click(sender As Object, e As EventArgs)
MessageBox.Show("Find")
End Sub
Private Sub Undo_Click(sender As Object, e As EventArgs)
MessageBox.Show("Undo")
End Sub
End Class
Program 7:( addition, deletion, updation) output not came
CODING:
Public Class Form1
Dim genderList As New List(Of String)
Private Sub SubmitButton_Click(sender As Object, e As EventArgs)
Handles
SubmitButton.Click
Dim gender As String = GenderTextBox.Text
genderList.Add(gender)
MessageBox.Show("Gender added successfully.")
End Sub
Private Sub AddButton_Click(sender As Object, e As EventArgs)
Handles
AddButton.Click
' Add your code to handle adding a new record here
End Sub
Private Sub DeleteButton_Click(sender As Object, e As EventArgs)
Handles
DeleteButton.Click
' Add your code to handle deleting a record here
End Sub
Private Sub UpdateButton_Click(sender As Object, e As EventArgs)
Handles
UpdateButton.Click
' Add your code to handle updating a record here
End Sub
End Class
Design window:
Output:
Program 8: date and time (output ok)
Coding:
Public Class Form1
' Button1 - Display Current Date and Time
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles
Button1.Click
' Get the current date and time
Dim currentDateTime As DateTime = DateTime.Now
' Display the current date and time
MessageBox.Show("Current Date and Time: " &
currentDateTime.ToString(), "Date & Time", MessageBoxButtons.OK,
MessageBoxIcon.Information)
End Sub
' Function to Get Available Doctor Based on Time
Private Function GetAvailableDoctor(currentTime As DateTime) As String
Dim availableDoctor As String = ""
' Determine doctor availability based on time
If currentTime.Hour >= 6 AndAlso currentTime.Hour < 12 Then
availableDoctor = "Dr.1 (Morning)"
ElseIf currentTime.Hour >= 12 AndAlso currentTime.Hour < 18 Then
availableDoctor = "Dr.2 (Afternoon)"
Else
availableDoctor = "Dr.3 (Evening/Night)"
End If
Return availableDoctor
End Function
' Button2 - Display Available Doctor in TextBox1
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles
Button2.Click
Dim currentTime As DateTime = DateTime.Now
Dim availableDoctor As String = GetAvailableDoctor(currentTime)
' Display the available doctor in TextBox1
TextBox1.Text = "Available Doctor: " & availableDoctor
End Sub
End Class
Design window:
Output: