我正在使用visual basic来创建一个程序,记录从抽象基类派生的每小时和薪水员工。对于我的界面,用户将选择每小时或工资员工,如果每小时,表单显示小时和小时费率文本框。如果工资表单隐藏小时文本框并将小时费率更改为年薪。
我有一个循环设置如下:
For i As Integer = 0 To EmployeeList.Count - 1
Dim thisEmployee As Employee = EmployeeList(i)
Dim HourlyorAnnualrate As String = Nothing
Dim Hours As String = Nothing
If TypeOf (thisEmployee) Is HourlyEmployee Then
HourlyorAnnualrate = CType(thisEmployee, HourlyEmployee).decRate
Hours = CType(thisEmployee, HourlyEmployee).decHours
TotalHourlyRate += thisEmployee.WeeklyGrossPay()
End If
If TypeOf (thisEmployee) Is SalariesEmployee Then
HourlyorAnnualrate = CType(thisEmployee, SalariesEmployee).decSalary
TotalSalariesRate += thisEmployee.WeeklyGrossPay()
End If
我在buttonclick上的文本框中添加了以下信息:
Private Sub btnPayroll_Click(sender As Object, e As EventArgs) Handles btnPayroll.Click
txtRecord.Text = "Total number of employees: " & vbTab & vbTab & EmployeeList.Count & vbCrLf & _
"Number of salaries employees: " & vbTab & SalariesEmployeeList.Count & vbCrLf & _
"Number of hourly employees: " & vbTab & vbTab & HourlyEmployeeList.Count & vbCrLf & _
"Total salaries employee weekly payroll: " & vbTab & vbTab & FormatCurrency(TotalSalariesRate) & vbCrLf & _
"Total hourly employee weekly payroll: " & vbTab & vbTab & FormatCurrency(TotalHourlyRate) & vbCrLf & _
"Total weekly payroll: " & vbTab & vbTab & FormatCurrency(TotalSalariesRate + TotalHourlyRate)
End Sub
我遇到的问题是用户可以选择薪水员工并且工作正常但是如果他们然后选择每小时员工,则记录每周总薪水并将其添加到TotalSalaries rate和TotalHourlyRate。
无论如何我可以防止这种情况发生吗?我尝试在每次点击按钮后取消选中单选按钮,但由于这是一个循环我仍然会记录不正确。
非常感谢任何帮助!
答案 0 :(得分:0)
我必须将子过程中的值设置为0,现在效果很好!