0% found this document useful (0 votes)
1 views6 pages

# Visual Basic Programming Solution 2

The document provides complete implementations for 10 Visual Basic Windows Forms Applications using Visual Studio 2019, including programs for printing numbers, dividing integers, tax calculations, and more. Each program includes a description of controls, code snippets, and implementation notes for creating the applications. Basic error handling is included in each program to manage invalid inputs.

Uploaded by

maazbintariq46
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views6 pages

# Visual Basic Programming Solution 2

The document provides complete implementations for 10 Visual Basic Windows Forms Applications using Visual Studio 2019, including programs for printing numbers, dividing integers, tax calculations, and more. Each program includes a description of controls, code snippets, and implementation notes for creating the applications. Basic error handling is included in each program to manage invalid inputs.

Uploaded by

maazbintariq46
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

# Visual Basic Windows Forms Applications in Visual Studio 2019

Here are complete implementations for all 10 programs as Windows Forms Applications
in Visual Studio 2019:

## 1. Program to Print 1 to 10 Natural Numbers

**Controls:**
- Button (btnPrintNumbers)
- ListBox (lstNumbers)

**Code:**
```vb
Public Class Form1
Private Sub btnPrintNumbers_Click(sender As Object, e As EventArgs) Handles
btnPrintNumbers.Click
lstNumbers.Items.Clear()
For i As Integer = 1 To 10
lstNumbers.Items.Add("Number " & i)
Next
End Sub
End Class
```

## 2. Program to Divide Two Integers

**Controls:**
- TextBox (txtNum1, txtNum2)
- Button (btnDivide)
- Label (lblResult)

**Code:**
```vb
Public Class Form1
Private Sub btnDivide_Click(sender As Object, e As EventArgs) Handles
btnDivide.Click
Try
Dim num1 As Integer = Integer.Parse(txtNum1.Text)
Dim num2 As Integer = Integer.Parse(txtNum2.Text)

If num2 = 0 Then
lblResult.Text = "Cannot divide by zero"
Else
Dim result As Double = num1 / num2
lblResult.Text = "Result: " & Math.Round(result, 2)
End If
Catch ex As Exception
lblResult.Text = "Please enter valid numbers"
End Try
End Sub
End Class
```

## 3. Tax Subtraction Calculator

**Controls:**
- TextBox (txtAmount, txtTaxRate)
- Button (btnCalculate)
- Label (lblNetAmount)
**Code:**
```vb
Public Class Form1
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles
btnCalculate.Click
Try
Dim amount As Decimal = Decimal.Parse(txtAmount.Text)
Dim taxRate As Decimal = Decimal.Parse(txtTaxRate.Text)
Dim taxAmount As Decimal = amount * (taxRate / 100)
Dim netAmount As Decimal = amount - taxAmount

lblNetAmount.Text = $"Net Amount: {netAmount.ToString("C")}" &


$"{vbCrLf}Tax Amount: {taxAmount.ToString("C")}"
Catch ex As Exception
lblNetAmount.Text = "Please enter valid numbers"
End Try
End Sub
End Class
```

## 4. Print Name Five Times

**Controls:**
- TextBox (txtName)
- Button (btnPrintName)
- ListBox (lstOutput)

**Code:**
```vb
Public Class Form1
Private Sub btnPrintName_Click(sender As Object, e As EventArgs) Handles
btnPrintName.Click
lstOutput.Items.Clear()
If String.IsNullOrEmpty(txtName.Text) Then
lstOutput.Items.Add("Please enter your name")
Return
End If

For i As Integer = 1 To 5
lstOutput.Items.Add($"{i}. {txtName.Text}")
Next
End Sub
End Class
```

## 5. Add Two Integers (Windows Form Version)

**Controls:**
- TextBox (txtNum1, txtNum2)
- Button (btnAdd)
- Label (lblResult)

**Code:**
```vb
Public Class Form1
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
Try
Dim num1 As Integer = Integer.Parse(txtNum1.Text)
Dim num2 As Integer = Integer.Parse(txtNum2.Text)
lblResult.Text = $"Sum: {num1 + num2}"
Catch ex As Exception
lblResult.Text = "Please enter valid integers"
End Try
End Sub
End Class
```

## 6. Print "PINISTAN" Ten Times

**Controls:**
- Button (btnPrint)
- ListBox (lstOutput)

**Code:**
```vb
Public Class Form1
Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles
btnPrint.Click
lstOutput.Items.Clear()
For i As Integer = 1 To 10
lstOutput.Items.Add($"{i}. PINISTAN")
Next
End Sub
End Class
```

## 7. Check Even or Odd

**Controls:**
- TextBox (txtNumber)
- Button (btnCheck)
- Label (lblResult)

**Code:**
```vb
Public Class Form1
Private Sub btnCheck_Click(sender As Object, e As EventArgs) Handles
btnCheck.Click
Try
Dim number As Integer = Integer.Parse(txtNumber.Text)
If number Mod 2 = 0 Then
lblResult.Text = $"{number} is Even"
Else
lblResult.Text = $"{number} is Odd"
End If
Catch ex As Exception
lblResult.Text = "Please enter a valid integer"
End Try
End Sub
End Class
```

## 8. Multiply Two Integers

**Controls:**
- TextBox (txtNum1, txtNum2)
- Button (btnMultiply)
- Label (lblResult)

**Code:**
```vb
Public Class Form1
Private Sub btnMultiply_Click(sender As Object, e As EventArgs) Handles
btnMultiply.Click
Try
Dim num1 As Integer = Integer.Parse(txtNum1.Text)
Dim num2 As Integer = Integer.Parse(txtNum2.Text)
lblResult.Text = $"Product: {num1 * num2}"
Catch ex As Exception
lblResult.Text = "Please enter valid integers"
End Try
End Sub
End Class
```

## 9. Marks to Grades Converter

**Controls:**
- TextBox (txtMarks)
- Button (btnCalculateGrade)
- Label (lblGrade)

**Code:**
```vb
Public Class Form1
Private Sub btnCalculateGrade_Click(sender As Object, e As EventArgs) Handles
btnCalculateGrade.Click
Try
Dim marks As Integer = Integer.Parse(txtMarks.Text)

Select Case marks


Case Is >= 90
lblGrade.Text = "Grade: A"
Case Is >= 80
lblGrade.Text = "Grade: B"
Case Is >= 70
lblGrade.Text = "Grade: C"
Case Is >= 60
lblGrade.Text = "Grade: D"
Case Else
lblGrade.Text = "Grade: F"
End Select
Catch ex As Exception
lblGrade.Text = "Please enter valid marks (0-100)"
End Try
End Sub
End Class
```

## 10. Small Calculator (All Operations)

**Controls:**
- TextBox (txtNum1, txtNum2)
- Buttons (btnAdd, btnSubtract, btnMultiply, btnDivide)
- Label (lblResult)
**Code:**
```vb
Public Class Form1
Private Sub Calculate(operation As String)
Try
Dim num1 As Double = Double.Parse(txtNum1.Text)
Dim num2 As Double = Double.Parse(txtNum2.Text)
Dim result As Double

Select Case operation


Case "+"
result = num1 + num2
Case "-"
result = num1 - num2
Case "*"
result = num1 * num2
Case "/"
If num2 = 0 Then
lblResult.Text = "Cannot divide by zero"
Return
End If
result = num1 / num2
End Select

lblResult.Text = $"Result: {Math.Round(result, 2)}"


Catch ex As Exception
lblResult.Text = "Please enter valid numbers"
End Try
End Sub

Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click


Calculate("+")
End Sub

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


btnSubtract.Click
Calculate("-")
End Sub

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


btnMultiply.Click
Calculate("*")
End Sub

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


btnDivide.Click
Calculate("/")
End Sub
End Class
```

## Implementation Notes:

1. For each program, create a new Windows Forms App (.NET Framework) project in
Visual Studio 2019
2. Design the form by dragging controls from the Toolbox
3. Set proper names for controls using the Properties window
4. Double-click buttons to create click event handlers
5. Copy the provided code into the appropriate event handlers
6. Set the form titles to match the program purpose
7. Adjust the UI layout as needed for better appearance

Each program includes basic error handling to manage invalid inputs. You can
enhance the UI with additional labels, group boxes, or formatting as needed.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy