' Validation to ensure text is numeric If Not Double.TryParse(txtNum1.Text, num1) OrElse Not Double.TryParse(txtNum2.Text, num2) Then MessageBox.Show("Please enter valid numbers") Exit Sub End If
BCA lab manuals typically categorise programs into console applications, Windows forms (GUI), and database connectivity. 1. Basic Console & Logic Programs
: Wrap any risky code in this safety net. vb net lab programs for bca students fix
This program teaches how to use TextBoxes, Labels, and Buttons to create a functional interface.
✅ Always use For...Next loops for a fixed number of iterations; it’s harder to mess up than Do While . 5. Input Validation: Crashing on Empty Boxes ' Validation to ensure text is numeric If Not Double
End Sub
Public Class Form1 Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click Compute("+") End Sub Private Sub btnSubtract_Click(sender As Object, e As EventArgs) Handles btnSubtract.Click Compute("-") End Sub Private Sub Compute(operation As String) If String.IsNullOrWhiteSpace(txtNum1.Text) Or String.IsNullOrWhiteSpace(txtNum2.Text) Then MessageBox.Show("Please enter values in both fields.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If Dim n1, n2, result As Double If Double.TryParse(txtNum1.Text, n1) AndAlso Double.TryParse(txtNum2.Text, n2) Then Select Case operation Case "+" : result = n1 + n2 Case "-" : result = n1 - n2 Case "/" If n2 = 0 Then MessageBox.Show("Division by zero is not allowed.", "Math Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If result = n1 / n2 End Select lblResult.Text = "Result: " & result.ToString() Else MessageBox.Show("Please enter valid numeric digits.", "Format Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End If End Sub End Class Use code with caution. Common Bugs & Fixes This program teaches how to use TextBoxes, Labels,
Always keep Option Explicit On and Option Strict On at the top of your code. It forces you to write better, bug-free code.
' Validation to ensure text is numeric If Not Double.TryParse(txtNum1.Text, num1) OrElse Not Double.TryParse(txtNum2.Text, num2) Then MessageBox.Show("Please enter valid numbers") Exit Sub End If
BCA lab manuals typically categorise programs into console applications, Windows forms (GUI), and database connectivity. 1. Basic Console & Logic Programs
: Wrap any risky code in this safety net.
This program teaches how to use TextBoxes, Labels, and Buttons to create a functional interface.
✅ Always use For...Next loops for a fixed number of iterations; it’s harder to mess up than Do While . 5. Input Validation: Crashing on Empty Boxes
End Sub
Public Class Form1 Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click Compute("+") End Sub Private Sub btnSubtract_Click(sender As Object, e As EventArgs) Handles btnSubtract.Click Compute("-") End Sub Private Sub Compute(operation As String) If String.IsNullOrWhiteSpace(txtNum1.Text) Or String.IsNullOrWhiteSpace(txtNum2.Text) Then MessageBox.Show("Please enter values in both fields.", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Warning) Exit Sub End If Dim n1, n2, result As Double If Double.TryParse(txtNum1.Text, n1) AndAlso Double.TryParse(txtNum2.Text, n2) Then Select Case operation Case "+" : result = n1 + n2 Case "-" : result = n1 - n2 Case "/" If n2 = 0 Then MessageBox.Show("Division by zero is not allowed.", "Math Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Exit Sub End If result = n1 / n2 End Select lblResult.Text = "Result: " & result.ToString() Else MessageBox.Show("Please enter valid numeric digits.", "Format Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End If End Sub End Class Use code with caution. Common Bugs & Fixes
Always keep Option Explicit On and Option Strict On at the top of your code. It forces you to write better, bug-free code.