Public Class Form1
Dim totalPieces As Integer = 0
Dim totalPay As Double = 0.0
Dim workerCount As Integer = 0
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles [Link]
Dim name As String = [Link]
Dim pieces As Integer
If [Link](name) Then
[Link]("Please enter a name.", "Validation Error", [Link],
[Link])
Return
End If
''Let's use the tryparse method to validate the pieces text box else it'll return 0
If Not [Link]([Link], pieces) Then
[Link]("Please enter a valid number of pieces.", "Validation Error", [Link],
[Link])
End If
Dim pricePerPiece As Integer
If pieces <= 200 Then
pricePerPiece = 60
ElseIf pieces <= 400 Then
pricePerPiece = 65
ElseIf pieces <= 600 Then
pricePerPiece = 70
Else
pricePerPiece = 75
End If
Dim earnedAmount As Double = pieces * pricePerPiece
totalPieces += pieces
totalPay += earnedAmount
workerCount += 1
'' Let's format this displayed value in a dialog box
[Link]($"Amount earned by {name}: {earnedAmount:C}", "Earnings", [Link],
[Link])
End Sub
Private Sub btnSummary_Click(sender As Object, e As EventArgs) Handles [Link]
If workerCount = 0 Then
[Link]("No data to summarize.", "Summary", [Link],
[Link])
Return
End If
Dim averagePay As Double = totalPay / workerCount
[Link]($"Total Pieces: {totalPieces}" & vbCrLf &
$"Total Pay: {totalPay:C}" & vbCrLf &
$"Average Pay per Worker: {averagePay:C}", "Summary", [Link],
[Link])
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles [Link]
[Link]()
[Link]()
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles [Link]
Dim result As DialogResult = [Link]("Are you sure you want to close?", "Close Confirmation",
[Link], [Link])
If result = [Link] Then
Close()
End If
End Sub
End Class