VB代码急用

来源:百度知道 编辑:UC知道 时间:2024/06/01 22:19:07
50元 <10小时
上网费用 3元一小时 10至30小时
2元一小时 >30小时
当费用大于168元时就取168元

Private time1, time2 As Date
Private a As Integer
Private Sub Command1_Click()'开始上网
time1 = Now()
MsgBox time1
Form1.Command1.Visible = False
Form1.Command2.Visible = True
End Sub

Private Sub Command2_Click() '结账下机
time2 = Now()
a = hour(time2 - time1)
MsgBox a
Form1.Command1.Visible = True
If a < 10 Then
MsgBox "您上网的花费为50元整"
End If
If a >= 10 And a < 30 Then
MsgBox "您上网的花费为" & 3 * a & "元整"
End If
If a >= 30 And 2 * a < 168 Then
MsgBox "您上网的花费为" & 2 * a & "元整"
End If
If a * 2 >= 168 Then
MsgBox "您上网的花费优惠之后为168元整"
End If

End Sub

Private Sub Form_Load()
Form1.Command2.Visible = False
End Sub

a为上网时间,b为费用
If a < 10 Then b = 50
If 10 < a < 30 Then b = a * 3
If a > 30 Then b = a * 2
If b > 168 Then b = 168