一道VB 程序题,请求帮忙。要详细程序哦!

某航空公司规定在7~9月份,如果订票数超过20张,则票价优惠15%,如果超过10张则票价优惠5%,在1~5月份、10月份和11月份,如果订票数超过20张,则票价优惠25%... 某航空公司规定在7~9月份,如果订票数超过20张,则票价优惠15%,如果超过10张则票价优惠5%,在1~5月份、10月份和11月份,如果订票数超过20张,则票价优惠25%,如果超过10张,则票价优惠15%。从窗体文本框中输入票价、月份以及订票数,并显示出所需金额。 展开
 我来答
万利Michael
推荐于2016-08-17 · 超过25用户采纳过TA的回答
知道答主
回答量:48
采纳率:0%
帮助的人:31.2万
展开全部

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上运行通过,未出错,可能还需要作此些小的调整,供你参考吧!

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式