0

助けてください。シンプルなフライト予約システムを作成しました。ユーザーが計算ボタンを選択すると、コンボボックス オプションから選択した大人と子供の人数分の料金が計算されます。計算は、コンボ ボックス 1 とコンボ ボックス 2 での選択に応じて、try catch と if ステートメント内で作成されます。モジュールを作成し、モジュール内に計算関数を配置し、計算ボタンで関数を呼び出す必要があります。フライトの料金は、選択した目的地によって異なります。

これはプログラムのソース コードです。ご協力をお願いいたします。

パブリック クラス Form1

Private Sub btncalculateprice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncalculateprice.Click
    Dim PricechildrenLocal As Integer = 1200
    Dim PriceadultsLocal As Integer = 12000
    Dim totalAdults As Integer
    Dim totalChildren As Integer
    Dim totalPrice As Integer
    Dim totalPrice1 As Integer
    Dim totalPrice2 As Integer


    Try

        If cmbadults.Text = 0 Then
            totalAdults += 0
        End If
        If cmbadults.Text = 1 Then
            totalAdults += 1
        End If
        If cmbadults.Text = 2 Then
            totalAdults += 2
        End If
        If cmbadults.Text = 3 Then
            totalAdults += 3
        End If
        If cmbadults.Text = 4 Then
            totalAdults += 4
        End If
        If cmbadults.Text = 5 Then
            totalAdults += 5
        End If
        If cmbadults.Text = 6 Then
            totalAdults += 6
        End If
        If cmbadults.Text = 7 Then
            totalAdults += 7
        End If
        If cmbadults.Text = 8 Then
            totalAdults += 8
        End If
        If cmbadults.Text = 9 Then
            totalAdults += 9
        End If
        If cmbadults.Text = 10 Then
            totalAdults += 10
        End If
    Catch ex As Exception

    End Try



    Try

        If cmbchildren.Text = 0 Then
            totalChildren += 0
        End If
        If cmbchildren.Text = 1 Then
            totalChildren += 1
        End If
        If cmbchildren.Text = 2 Then
            totalChildren += 2
        End If
        If cmbchildren.Text = 3 Then
            totalChildren += 3
        End If
        If cmbchildren.Text = 4 Then
            totalChildren += 4
        End If
        If cmbchildren.Text = 5 Then
            totalChildren += 5
        End If
        If cmbchildren.Text = 6 Then
            totalChildren += 6
        End If
        If cmbchildren.Text = 7 Then
            totalChildren += 7
        End If
        If cmbchildren.Text = 8 Then
            totalChildren += 8
        End If
        If cmbchildren.Text = 9 Then
            totalChildren += 9
        End If
        If cmbchildren.Text = 10 Then
            totalChildren += 10
        End If
    Catch ex As Exception

    End Try


    Try

        If ComboBox1.Text = "Bloemfontien Airport (BFN)" And ComboBox2.Text = "Cape Town International (CPT)" Then
            totalPrice1 = totalChildren * PricechildrenLocal
            totalPrice2 = totalAdults * PriceadultsLocal
        ElseIf ComboBox1.Text = "Bloemfontien Airport (BFN)" And ComboBox2.Text = "King Shaka International Airport (DBN)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 100
            totalPrice2 = totalAdults * PriceadultsLocal + 150
        ElseIf ComboBox1.Text = "Bloemfontien Airport (BFN)" And ComboBox2.Text = "O.R Tambo International Airport (JHB)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 100
            totalPrice2 = totalAdults * PriceadultsLocal + 150
        ElseIf ComboBox1.Text = "Bloemfontien Airport (BFN)" And ComboBox2.Text = "Lanseria Airport (JHB)" Then
            totalPrice1 = totalChildren * PricechildrenLocal - 1000
            totalPrice2 = totalAdults * PriceadultsLocal - 2000
        ElseIf ComboBox1.Text = "Bloemfontien Airport (BFN)" And ComboBox2.Text = "Polokwane International Airport (PLK)" Then
            totalPrice1 = totalChildren * PricechildrenLocal - 500
            totalPrice2 = totalAdults * PriceadultsLocal - 1000
        ElseIf ComboBox1.Text = "Bloemfontien Airport (BFN)" And ComboBox2.Text = "Port Elizabeth Airport (PE)" Then
            totalPrice1 = totalChildren * PricechildrenLocal
            totalPrice2 = totalAdults * PriceadultsLocal

        ElseIf ComboBox1.Text = "Cape Town International (CPT)" And ComboBox2.Text = "Bloemfontien Airport (BFN)" Then
            totalPrice1 = totalChildren * PricechildrenLocal
            totalPrice2 = totalAdults * PriceadultsLocal
        ElseIf ComboBox1.Text = "Cape Town International (CPT)" And ComboBox2.Text = "King Shaka International Airport (DBN)" Then
            totalPrice1 = totalChildren * PricechildrenLocal
            totalPrice2 = totalAdults * PriceadultsLocal
        ElseIf ComboBox1.Text = "Cape Town International (CPT)" And ComboBox2.Text = "O.R Tambo International Airport (JHB)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 100
            totalPrice2 = totalAdults * PriceadultsLocal + 150
        ElseIf ComboBox1.Text = "Cape Town International (CPT)" And ComboBox2.Text = "Lanseria Airport (JHB)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 150
            totalPrice2 = totalAdults * PriceadultsLocal + 200
        ElseIf ComboBox1.Text = "Cape Town International (CPT)" And ComboBox2.Text = "Polokwane International Airport (PLK)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 150
            totalPrice2 = totalAdults * PriceadultsLocal + 200
        ElseIf ComboBox1.Text = "Cape Town International (CPT)" And ComboBox2.Text = "Port Elizabeth Airport (PE)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 150
            totalPrice2 = totalAdults * PriceadultsLocal + 200



        ElseIf ComboBox1.Text = "King Shaka International Airport (DBN)" And ComboBox2.Text = "Bloemfontien Airport (BFN)" Then
            totalPrice1 = totalChildren * PricechildrenLocal
            totalPrice2 = totalAdults * PriceadultsLocal
        ElseIf ComboBox1.Text = "King Shaka International Airport (DBN)" And ComboBox2.Text = "Cape Town International (CPT)" Then
            totalPrice1 = totalChildren * PricechildrenLocal
            totalPrice2 = totalAdults * PriceadultsLocal
        ElseIf ComboBox1.Text = "King Shaka International Airport (DBN)" And ComboBox2.Text = "O.R Tambo International Airport (JHB)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 100
            totalPrice2 = totalAdults * PriceadultsLocal + 150
        ElseIf ComboBox1.Text = "King Shaka International Airport (DBN)" And ComboBox2.Text = "Lanseria Airport (JHB)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 150
            totalPrice2 = totalAdults * PriceadultsLocal + 200
        ElseIf ComboBox1.Text = "King Shaka International Airport (DBN)" And ComboBox2.Text = "Polokwane International Airport (PLK)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 150
            totalPrice2 = totalAdults * PriceadultsLocal + 200
        ElseIf ComboBox1.Text = "King Shaka International Airport (DBN)" And ComboBox2.Text = "Port Elizabeth Airport (PE)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 150
            totalPrice2 = totalAdults * PriceadultsLocal + 200


        ElseIf ComboBox1.Text = "O.R Tambo International Airport (JHB)" And ComboBox2.Text = "Bloemfontien Airport (BFN)" Then
            totalPrice1 = totalChildren * PricechildrenLocal
            totalPrice2 = totalAdults * PriceadultsLocal
        ElseIf ComboBox1.Text = "O.R Tambo International Airport (JHB)" And ComboBox2.Text = "Cape Town International (CPT)" Then
            totalPrice1 = totalChildren * PricechildrenLocal
            totalPrice2 = totalAdults * PriceadultsLocal
        ElseIf ComboBox1.Text = "O.R Tambo International Airport (JHB)" And ComboBox2.Text = "Lanseria Airport (JHB)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 100
            totalPrice2 = totalAdults * PriceadultsLocal + 150
        ElseIf ComboBox1.Text = "O.R Tambo International Airport (JHB)" And ComboBox2.Text = "Polokwane International Airport (PLK)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 150
            totalPrice2 = totalAdults * PriceadultsLocal + 200
        ElseIf ComboBox1.Text = "Cape Town International (CPT)" And ComboBox2.Text = "Port Elizabeth Airport (PE)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 150
            totalPrice2 = totalAdults * PriceadultsLocal + 200


        ElseIf ComboBox1.Text = "Lanseria Airport (JHB)" And ComboBox2.Text = "Bloemfontien Airport (BFN)" Then
            totalPrice1 = totalChildren * PricechildrenLocal - 500
            totalPrice2 = totalAdults * PriceadultsLocal - 1000
        ElseIf ComboBox1.Text = "Lanseria Airport (JHB)" And ComboBox2.Text = "Cape Town International (CPT)" Then
            totalPrice1 = totalChildren * PricechildrenLocal
            totalPrice2 = totalAdults * PriceadultsLocal
        ElseIf ComboBox1.Text = "Lanseria Airport (JHB)" And ComboBox2.Text = "King Shaka International Airport (DBN)" Then
            totalPrice1 = totalChildren * PricechildrenLocal
            totalPrice2 = totalAdults * PriceadultsLocal
        ElseIf ComboBox1.Text = "Lanseria Airport (JHB) (CPT)" And ComboBox2.Text = "O.R Tambo International Airport (JHB)" Then
            totalPrice1 = totalChildren * PricechildrenLocal - 500
            totalPrice2 = totalAdults * PriceadultsLocal - 1000
        ElseIf ComboBox1.Text = "Lanseria Airport (JHB)" And ComboBox2.Text = "Polokwane International Airport (PLK)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 150
            totalPrice2 = totalAdults * PriceadultsLocal + 200
        ElseIf ComboBox1.Text = "Lanseria Airport (JHB)" And ComboBox2.Text = "Port Elizabeth Airport (PE)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 150
            totalPrice2 = totalAdults * PriceadultsLocal + 200

        ElseIf ComboBox1.Text = "Polokwane International Airport (PLK)" And ComboBox2.Text = "Bloemfontien Airport (BFN)" Then
            totalPrice1 = totalChildren * PricechildrenLocal - 500
            totalPrice2 = totalAdults * PriceadultsLocal - 1000
        ElseIf ComboBox1.Text = "Polokwane International Airport (PLK)" And ComboBox2.Text = "Cape Town International (CPT)" Then
            totalPrice1 = totalChildren * PricechildrenLocal
            totalPrice2 = totalAdults * PriceadultsLocal
        ElseIf ComboBox1.Text = "Polokwane International Airport (PLK)" And ComboBox2.Text = "King Shaka International Airport (DBN)" Then
            totalPrice1 = totalChildren * PricechildrenLocal
            totalPrice2 = totalAdults * PriceadultsLocal
        ElseIf ComboBox1.Text = "Polokwane International Airport (PLK)" And ComboBox2.Text = "O.R Tambo International Airport (JHB)" Then
            totalPrice1 = totalChildren * PricechildrenLocal - 500
            totalPrice2 = totalAdults * PriceadultsLocal - 1000
        ElseIf ComboBox1.Text = "Polokwane International Airport (PLK)" And ComboBox2.Text = "Port Elizabeth Airport (PE)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 150
            totalPrice2 = totalAdults * PriceadultsLocal + 200

        ElseIf ComboBox1.Text = "Port Elizabeth Airport (PE)" And ComboBox2.Text = "Bloemfontien Airport (BFN)" Then
            totalPrice1 = totalChildren * PricechildrenLocal - 500
            totalPrice2 = totalAdults * PriceadultsLocal - 1000
        ElseIf ComboBox1.Text = "Port Elizabeth Airport (PE)" And ComboBox2.Text = "Cape Town International (CPT)" Then
            totalPrice1 = totalChildren * PricechildrenLocal
            totalPrice2 = totalAdults * PriceadultsLocal
        ElseIf ComboBox1.Text = "Port Elizabeth Airport (PE)" And ComboBox2.Text = "King Shaka International Airport (DBN)" Then
            totalPrice1 = totalChildren * PricechildrenLocal
            totalPrice2 = totalAdults * PriceadultsLocal
        ElseIf ComboBox1.Text = "Port Elizabeth Airport (PE)" And ComboBox2.Text = "O.R Tambo International Airport (JHB)" Then
            totalPrice1 = totalChildren * PricechildrenLocal - 500
            totalPrice2 = totalAdults * PriceadultsLocal - 1000
        ElseIf ComboBox1.Text = "Port Elizabeth Airport (PE)" And ComboBox2.Text = "Polokwane International Airport (PLK)" Then
            totalPrice1 = totalChildren * PricechildrenLocal + 150
            totalPrice2 = totalAdults * PriceadultsLocal + 200

        End If
    Catch ex As Exception

    End Try

    totalPrice = totalPrice1 + totalPrice2
    Price.Text = Format(totalPrice, "currency")
    Adults.Text = totalAdults
    Children.Text = totalChildren 

End Sub

Private Sub btnbookflight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnbookflight.Click
    Dim form As New Confirm
    If cmbadults.SelectedItem = "" Then
        MessageBox.Show("Please select the number of adults")
    Else
        If cmbchildren.SelectedItem = "" Then
            MessageBox.Show("Please select the number of children")
        Else

            If ComboBox1.SelectedItem = "" Then
                MessageBox.Show("Please select the depature destination")
            Else
                If ComboBox2.SelectedItem = "" Then
                    MessageBox.Show("Please select the going to destination")
                Else
                    Confirm.Show()
                End If
            End If
            End If
        End If

End Sub

Private Sub cmbadults_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmbadults.SelectedIndexChanged

End Sub

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Me.Close()

End Sub

Private Sub rbnoneway_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbnoneway.CheckedChanged
    If rbnoneway.Checked Then
        lblreturndate.Hide()
    Else
        lblreturndate.Show()
    End If
    If rbnoneway.Checked Then
        dtereturn.Hide()
    Else
        dtereturn.Show()
    End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    cmbtitle.Text = ""
    TextBox1.Text = ""
    TextBox2.Text = ""
    TextBox3.Text = ""
    TextBox4.Text = ""
    TextBox5.Text = ""
    TextBox6.Text = ""
    cmbadults.Text = ""
    cmbchildren.Text = ""
    ComboBox1.Text = ""
    ComboBox2.Text = ""
    dtedepature.Text = ""
    dtereturn.Text = ""
    rbnoneway.Checked = False
    rbnroundtrip.Checked = False
End Sub

クラス終了

4

1 に答える 1