Public Class PrimeForm Private Sub btnCheck_Click(sender As Object, e As EventArgs) Handles btnCheck.Click Dim num As Integer If Integer.TryParse(txtInput.Text, num) AndAlso num > 1 Then Dim isPrime As Boolean = True For i As Integer = 2 To Math.Sqrt(num) If num Mod i = 0 Then isPrime = False Exit For End If Next If isPrime Then lblOutput.Text = num & " is a Prime Number." Else lblOutput.Text = num & " is a Composite Number." End If Else lblOutput.Text = "Please enter an integer greater than 1." End If End Sub End Class Use code with caution. Common Error & Fix
What or unexpected behavior are you seeing? vb net lab programs for bca students fix
Replace Convert.ToInt32() with Integer.TryParse(Console.ReadLine(), num1) to safely handle non-numeric inputs without crashing. ByVal m2 As Integer
Public Class Form1 Private Sub btnCheck_Click(sender As Object, e As EventArgs) Handles btnCheck.Click Dim inputStr As String = txtInput.Text Dim reverseStr As String = StrReverse(inputStr) "Amit Sharma") studentResult.GetMarks(85
Public Class Student Protected RollNo As Integer Protected Name As String Public Sub GetStudentData(ByVal r As Integer, ByVal n As String) RollNo = r Name = n End Sub End Class Public Class Exam Inherits Student Private Marks(2) As Integer Private Total As Integer = 0 Public Sub GetMarks(ByVal m1 As Integer, ByVal m2 As Integer, ByVal m3 As Integer) Marks(0) = m1 Marks(1) = m2 Marks(2) = m3 End Sub Public Sub CalculateAndDisplay() Total = Marks(0) + Marks(1) + Marks(2) Console.WriteLine("--- Student Result ---") Console.WriteLine("Roll No: " & RollNo) Console.WriteLine("Name: " & Name) Console.WriteLine("Total Marks: " & Total) End Sub End Class Module LibraryModule Sub Main() Dim studentResult As New Exam() studentResult.GetStudentData(101, "Amit Sharma") studentResult.GetMarks(85, 90, 78) studentResult.CalculateAndDisplay() Console.ReadLine() End Sub End Module Use code with caution. Common Bugs & Fixes
The console window closes instantly after execution.
Use Application.StartupPath to dynamically define the database path so your project works on any computer.