如何声明变量和求和变量值
How to declare variables and sum up the variable values
您好,我想对这 3 个变量求和并将总和值自动填充到另一个变量 - Excel 上的 txtTotalMonthly Salary。
- txtLastMonthlyDrawnSalary
- txtAWS
- txt津贴
请问有人能指点一下吗?
Private Sub txtLastMonthlyDrawnSalary_Change()
If Me.txtLastMonthlyDrawnSalary.Value <> "" Then
Dim Product As Long
Product = Me.txtLastMonthlyDrawnSalary.Value * 12
Me.txtLastAnnualDrawnSalary.Value = Product
End If
If Me.txtLastMonthlyDrawnSalary.Value <> "" Then
Dim Sum As Long
Me.txtLastMonthlyDrawnSalary.Value Me.txtAWS.Value + Me.txtAllowance.Value = Sum
End If
End Sub
首先,作为一种好的做法,我会在开头声明所有变量。
所以从 DIM 产品开始......
另外,什么是 "Me"
另外,如果 txtlastmonthdrawnsalary 是数字,则不需要在末尾添加“.value”。
为了避免任何可能的错误,我在变量的末尾添加了 "z" 以将它们与 VB 变量区分开来。
我会从以下开始,如果还是不行,让我们看看它在哪里中断:
Private Sub txtLastMonthlyDrawnSalary_Change()
Dim Productz As Long, Sumz As Long, txtLastMonthlyDrawnSalary as long, txtLastAnnualDrawnSalary as long
If not txtLastMonthlyDrawnSalary = "" Then
Productz = txtLastMonthlyDrawnSalary * 12
txtLastAnnualDrawnSalary = Productz
End If
If not txtLastMonthlyDrawnSalary = "" Then
sumz = txtLastMonthlyDrawnSalary + txtAWS + txtAllowance
End If
End Sub
您好,我想对这 3 个变量求和并将总和值自动填充到另一个变量 - Excel 上的 txtTotalMonthly Salary。
- txtLastMonthlyDrawnSalary
- txtAWS
- txt津贴
请问有人能指点一下吗?
Private Sub txtLastMonthlyDrawnSalary_Change()
If Me.txtLastMonthlyDrawnSalary.Value <> "" Then
Dim Product As Long
Product = Me.txtLastMonthlyDrawnSalary.Value * 12
Me.txtLastAnnualDrawnSalary.Value = Product
End If
If Me.txtLastMonthlyDrawnSalary.Value <> "" Then
Dim Sum As Long
Me.txtLastMonthlyDrawnSalary.Value Me.txtAWS.Value + Me.txtAllowance.Value = Sum
End If
End Sub
首先,作为一种好的做法,我会在开头声明所有变量。
所以从 DIM 产品开始...... 另外,什么是 "Me"
另外,如果 txtlastmonthdrawnsalary 是数字,则不需要在末尾添加“.value”。
为了避免任何可能的错误,我在变量的末尾添加了 "z" 以将它们与 VB 变量区分开来。
我会从以下开始,如果还是不行,让我们看看它在哪里中断:
Private Sub txtLastMonthlyDrawnSalary_Change()
Dim Productz As Long, Sumz As Long, txtLastMonthlyDrawnSalary as long, txtLastAnnualDrawnSalary as long
If not txtLastMonthlyDrawnSalary = "" Then
Productz = txtLastMonthlyDrawnSalary * 12
txtLastAnnualDrawnSalary = Productz
End If
If not txtLastMonthlyDrawnSalary = "" Then
sumz = txtLastMonthlyDrawnSalary + txtAWS + txtAllowance
End If
End Sub