我写了一个程序,一旦员工输入他们的信息和时间,就可以计算工资单数据。我在从一种形式到另一种形式的变量中读取数据时遇到问题。我试图做的是从一个名为TimeSheet的表单中读取另一个名为Payroll_Submission的表单。这是我到目前为止的代码,我真的需要从其他表单中获取数据来进行计算。如果您需要我的TimeSheet代码,请告诉我,这很长,所以这次我没有附上它。
Public Class Payroll_Submission
Private Sub Payroll_Submission_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim counter As Integer
counter = 0
lblEmployee.Text = TimeSheet.EmpName
lblSuperName.Text = TimeSheet.Supervisor
lblReport.Text = TimeSheet.Period
If Not TimeSheet.flag Then
lblHoursWorked.Text = TimeSheet.txtMon1 + TimeSheet.txtTues1 + TimeSheet.txtWed1 + TimeSheet.txtThurs1 + TimeSheet.txtFri1 + TimeSheet.txtSat1 + TimeSheet.txtSun1
If lblOvertimeHours.Text > 40 Then
lblRegHours.Text = 40
lblRegHours.Text = lblHoursWorked.Text - 40
Else
lblRegHours.Text = lblHoursWorked.Text
lblOvertimeHours.Text = 0
End If
lblOvertimeHours.Text = "$15"
lblRateOver.Text = "$22.50"
HourlyPay.Text = Convert.ToInt32(lblRegHours.Text) * 15
lblOvertimeHours.Text = Convert.ToInt32(lblOvertimeHours.Text) * 22.5
lblGrossPay.Text = Convert.ToInt32(HourlyPay.Text) + Convert.ToInt32(lblOvertimeHours.Text)
If TimeSheet.chk1.Checked Then
counter = counter + 1
End If
If TimeSheet.chk2.Checked Then
counter = counter + 1
End If
If TimeSheet.chk3.Checked Then
counter = counter + 1
End If
If TimeSheet.chk4.Checked Then
counter = counter + 1
End If
If TimeSheet.chk5.Checked Then
counter = counter + 1
End If
If TimeSheet.chk6.Checked Then
counter = counter + 1
End If
If TimeSheet.chk7.Checked Then
counter = counter + 1
End If
lblPTOHours.Text = counter
End If
HourlyPay.Text = Convert.ToInt32(lblRegHours.Text) * 15
lblOvertimeHours.Text = Convert.ToInt32(lblOvertimeHours.Text) * 22.5
lblGrossPay.Text = Convert.ToInt32(lblRegHours.Text) + Convert.ToInt32(lblOvertimeHours.Text)
End Sub
结束班
答案 0 :(得分:1)
如果我理解你想要正确做什么,那实际上非常简单。 在您的时间表表格中,您是否像这样打电话给您的工资表?
dim payroll as new Payroll_Submission
payroll.showdialog()
如果你这样做,你应该可以通过以下方式访问工资单上的所有控件:
payroll.lblEmployee.Text = Me.EmpName
等等。
然后,这会将Payroll表单上的每个标签和其他控件设置为Timesheets表单中的变量。 在执行.showdialog之前,您需要确保在Payroll表单上设置控件。
它应该都是这样的:
dim payroll as new Payroll_Submission
payroll.lblEmployee.Text = Me.EmpName
payroll.lblSuperName.Text = Me.Supervisor
payroll.showdialog()
答案 1 :(得分:0)
假设您从Payroll_Submission
表单创建Timesheet
表单,我会考虑在您的Payroll_Submission
表单中添加第二个构造函数:
Private _ts As Form
Public Sub New(ts As Form)
Me.New()
_ts = ts
End Sub
创建表单时,通过构造函数
传递对表单的引用 Dim ps As New Payroll_Submission(Me)
然后,将TimeSheet
的引用更改为_ts
后,您的代码应该可以正常运行。
只需查看您的代码,您也可以将其缩小一点,以便计算counter
:
Dim cbs As New List(Of CheckBox) From _
{ _
_ts.chk1, _ts.chk2, _ts.chk3, _
_ts.chk4, _ts.chk5, _ts.chk6, _
_ts.chk7 _
}
Dim counter = cbs.Where(Function (cb) cb.Checked).Count()
答案 2 :(得分:0)
将您在Timesheet表单中的变量声明为Friend。例如
Public Class Timesheet
Friend EmpName As String
Friend Supervisor As String