一道VB 程序题,请求帮忙。要详细程序哦!
Imports System
Imports System.Windows.Forms
Public Class Ticket
Dim InteQuantity, DateMonth As Integer '数量与日期变量
Dim DblPrice, DblTotal, DblDiscount, DblRates As Double '单价、合计金额、优惠比例及优惠后金额变量
Private Sub Ticket_Load(sender As Object, e As EventArgs) Handles Me.Load
Me.DateTimePicker1.Focus()
End Sub
Private Sub DateTimePicker1_CloseUp(sender As Object, e As EventArgs) Handles DateTimePicker1.CloseUp
DateMonth = Me.DateTimePicker1.Value.Month '取开始日期的月份
Me.TextBox1.Focus()
End Sub
Private Sub TextBox1_LostFocus(sender As Object, e As EventArgs) Handles TextBox1.LostFocus
Dim strMsg As String = "输入有误,必须输入正整数,其他输入将会四舍五入!"
If Trim(Me.TextBox1.Text) <> "" Then
InteQuantity = Trim(CInt(Me.TextBox1.Text))
If Not IsNumeric(InteQuantity) Then
MsgBox(strMsg)
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
ElseIf InteQuantity < 0 Then
MsgBox(strMsg)
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
Else
Me.TextBox2.Focus()
End If
Else
Me.TextBox1.Focus()
End If
End Sub
Private Sub TextBox2_LostFocus(sender As Object, e As EventArgs) Handles TextBox2.LostFocus
Dim strMsg As String = "输入有误,必须输入数字!"
If Trim(Me.TextBox2.Text) <> "" Then
DblPrice = Trim(CDbl(Me.TextBox2.Text))
If Not IsNumeric(DblPrice) Then
MsgBox(strMsg)
Me.TextBox2.Text = ""
Me.TextBox2.Focus()
End If
Else
Me.TextBox2.Focus()
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
DblTotal = InteQuantity * DblPrice '计算未优惠合计金额
DblDiscount = 0
Select Case DateMonth
Case DateMonth <= 5 And DateMonth = 10 And DateMonth = 11
If InteQuantity > 10 And InteQuantity <= 20 Then DblDiscount = 0.15
If InteQuantity > 20 Then DblDiscount = 0.25
Case DateMonth >= 7 And DateMonth <= 9
If InteQuantity > 10 And InteQuantity <= 20 Then DblDiscount = 0.05
If InteQuantity > 20 Then DblDiscount = 0.15
End Select
DblRates = InteQuantity * DblPrice * (1 - DblDiscount) '计算优惠后合计金额
Me.TextBox3.Text = DblTotal '显示合计金额
Me.TextBox4.Text = DblRates '显示优惠后的合计金额
Me.Label10.ForeColor = Color.Red
If DblRates = 0 Then
Me.Label10.Text = "注:您本次订票未享受优惠"
Else
Me.Label10.Text = "注:您本次订票共计享受" & Chr(13) & "优惠:" & DblTotal - DblRates & "元。" & Chr(13) & "优惠比例为" & DblDiscount * 100 & "%"
End If
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
DblTotal = 0 '部分变量归零,避免二次输入时计算错误
DblDiscount = 0
DblRates = 0
Me.DateTimePicker1.Value = Now
Me.DateTimePicker1.Focus()
Me.TextBox1.Text = ""
Me.TextBox2.Text = ""
Me.TextBox3.Text = ""
Me.TextBox4.Text = ""
Me.Label10.Text = ""
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
End
End Sub
End Class
匆匆忙忙写的,未作详细的调试,在VB.Net2012上运行通过,未出错,可能还需要作此些小的调整,供你参考吧!