新建From1(窗体),新建Command1(按钮CommandButton),代码:
Private Sub Command1_Click()
Debug.Print Bonus(3, 100)
Debug.Print Bonus(4, 100)
End Sub
Private Function Bonus(performance, salary)
If performance = 1 Then
Bonus = salary * 0.1
ElseIf performance = 2 Then
Bonus = salary * 0.09
ElseIf performance = 3 Then
Bonus = salary * 0.07
Else
Bonus = 0
End If
End Function
运行结果:
70
0