]Private Sub cmdcalculate_Click()
'Determined The Amount Due
Dim intpieces As Integer
Dim Curprice As Currency
Dim Curamountearned As Currency
intpieces = Val(txtpieces)
'Validate for missing data and enable summary button after
'the first order has been entered
If txtname.Text = "" Then
MsgBox "Please Enter Name", vbOKOnly, "Data Entry Error"
txtname.SetFocus
ElseIf Not IsNumeric(txtpieces.Text) Then
MsgBox "Please Enter a Positive Number for the Piece Count", _
vbOKOnly, "Data Entry Error"
With txtpieces
.Text = " "
.SetFocus
End With
Else
cmdsummary.Enabled = True
' Find person with greatest number of pieces
If intpieces > MintHighestpieces Then 'compare to current winner
MintHighestpieces = intpieces
Mstrhighname = txtname.Text
End If
'find pay rate
If intpieces < 200 Then
Curprice = 0.5
ElseIf intpieces < 400 Then
Curprice = 0.55
ElseIf intpieces < 600 Then
Curprice = 0.6
Else
Curprice = 0.65
End If
'calculate the pay
Curamountearned = intpieces * Curprice
lblamountearned.Caption = FormatCurrency(Curamountearned)
'add to totals
mintpiecesTotal = mintpiecesTotal + intpieces
Dim mintemployeecount As Integer
Mcurpaytotal = Mcurpaytotal + Curamountearned
End If
End Sub
Private Sub cmdclear_Click()
txtname.Text = ""
txtpieces.Text = ""
lblaverage.Caption = ""
lblmoney.Caption = ""
lblpieces = ""
lbltotalmoney = ""
lblamountearned = ""
End Sub
Private Sub cmdexit_Click()
End
End Sub
Private Sub cmdsummary_Click()
'Calculate the average and dispaly the totals
Dim curaveragepay As Currency
Dim strmessage As String
curaveragepay = Mcurpaytotal / mintemployeecount
strmessage = "Total number of pieces " + mintpiecesTotal + vbCrLf + _
"Average Pay: " + FormatCurrency(curaveragepay) + cbCrLf + _
"Person producing most: " + Mstrhighname & vbCrLf + _
" (produced " + MintHighestpieces + " pieces)"
MsgBox strmessage, vbOKOnly, "Piecework Summary"
End Sub
Private Sub Form_Load()
'Initialise the variables
MintHighestpieces = -1
End Sub
Private Sub Label1_Click()
'calculate the pay
Curamountearned = intpieces * Curprice
lblamountearned.Caption = FormatCurrency(Curamountearned)
End Sub
Private Sub Lblearned_Click()
End Sub