Are you a BCA student struggling with your VB.NET lab manual? Whether you are stuck on a logic error or just need a clean template to start with, this guide covers the most important programs you’ll face in your practical exams. 🏗️ 1. Simple Calculator (Basic Controls)

[Institutional Affiliation] Course: Bachelor of Computer Applications (BCA) Subject: Visual Programming using VB.NET

VB.NET doesn't support control arrays like VB6, so students must learn to use collections or handle multiple events with one subroutine. Use the Handles clause for multiple buttons.

Public Class CalculatorForm Dim firstValue As Double Dim secondValue As Double Dim op As String Dim isOpClicked As Boolean = False ' Shared event handler for all number buttons (0-9) Private Sub Number_Click(sender As Object, e As EventArgs) Handles btn1.Click, btn2.Click, btn3.Click ' Add all button handles Dim btn As Button = CType(sender, Button) ' FIX: Clear textbox if a fresh number is typed after clicking an operator If isOpClicked Then txtDisplay.Clear() isOpClicked = False End If txtDisplay.Text &= btn.Text End Sub Private Sub Operator_Click(sender As Object, e As EventArgs) Handles btnAdd.Click, btnSub.Click Dim btn As Button = CType(sender, Button) ' FIX: Validate that the textbox is not empty before storing the operator If Not String.IsNullOrEmpty(txtDisplay.Text) Then firstValue = Double.Parse(txtDisplay.Text) op = btn.Text isOpClicked = True End If End Sub Private Sub btnEqual_Click(sender As Object, e As EventArgs) Handles btnEqual.Click ' FIX: Ensure there is a value to compute If Not String.IsNullOrEmpty(txtDisplay.Text) AndAlso op <> "" Then secondValue = Double.Parse(txtDisplay.Text) Dim result As Double = 0 Select Case op Case "+" : result = firstValue + secondValue Case "-" : result = firstValue - secondValue ' FIX: Handle division by zero scenario safely Case "/" If secondValue = 0 Then txtDisplay.Text = "Error (Div by 0)" Exit Sub Else result = firstValue / secondValue End If End Select txtDisplay.Text = result.ToString() op = "" End If End Sub End Class Use code with caution. Key Fixes Applied:

Public Class frmCalculator Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click PerformOperation("Add") End Sub Private Sub PerformOperation(op As String) Dim num1, num2, result As Double ' Fix 1: Use TryParse to avoid FormatException If Double.TryParse(txtNum1.Text, num1) AndAlso Double.TryParse(txtNum2.Text, num2) Then Select Case op Case "Add" result = num1 + num2 Case "Subtract" result = num1 - num2 Case "Multiply" result = num1 * num2 Case "Divide" ' Fix 2: Check division by zero If num2 = 0 Then MessageBox.Show("Cannot divide by zero", "Error") Return End If result = num1 / num2 End Select lblResult.Text = "Result: " & result.ToString() Else MessageBox.Show("Please enter valid numbers", "Input Error") End If End Sub

VB.NET strictly enforces that all overloaded operators must be Shared and accept matching parameters. Leaving out Shared results in a critical compile-time error. 3. Windows Forms and Event-Driven Programming Program 3: Simple Scientific Calculator

Subtotal: $0

Your Cart is Empty!
TOP
0 Items
vb net lab programs for bca students fix