子过程值不会显示在输出中。有截图

时间:2016-03-24 16:28:45

标签: vba visual-studio

我无法在TotalCost子程序中获取要在输出屏幕中显示的值。它只显示零件

Ouput Screen. IT is supposed to show the total for the chairs and sofas plus separate tax and a grand total

Public Class Form1
    Private Sub btnProcess_Click(sender As Object, e As EventArgs) Handles btnProcess.Click

        Dim chairQuant, sofaQuant, chair, sofa, price, total, tax As Double
        Dim name, address, zip As String

        If Not DataOk() Then
            Dim msg As String = " Please make sure all data is entered correctly."
            MessageBox.Show(msg)
            Else
             InputData(chair, sofa, name, address, zip)
             TotalCost(price, total, tax, chairQuant, sofaQuant)
             ShowInvoice(name, address, zip, chairQuant, sofaQuant, price, tax, total)
        End If
    End Sub

    Function DataOk() As Boolean
        If (txtName.Text = "") Or (txtAddress.Text = "") Or (txtCity.Text = "") Or
            (Not IsNumeric(txtChairs.Text)) Or (Not IsNumeric(txtSofas.Text)) Then
            Return False
        Else
            Return True
        End If
    End Function

    Sub InputData(ByRef chairQuant As Double, ByRef sofaQuant As Double, ByRef name As String,
                  ByRef address As String, ByRef Zip As String)

        chairQuant = CDbl(txtChairs.Text)
        sofaQuant = CDbl(txtSofas.Text)
        name = txtName.Text
        address = txtAddress.Text
        Zip = txtCity.Text

    End Sub

    Sub TotalCost(ByRef price As Double, ByRef total As Double, ByRef tax As Double, chairQuant As Double,
               sofaQuant As Double)
        Dim chair As Double = (chairQuant) * (350)
        Dim sofa As Double = (sofaQuant) * (925)

        price = (chair + sofa)
        tax = (chair + sofa) * (0.05)
        total = (chair + sofa) * (1.05)
    End Sub
    Sub ShowInvoice(name As String, address As String, zip As String,
                 chairQuant As Double, sofaQuant As Double, price As Double,
                 tax As Double, total As Double)

        lstOutput.Items.Clear()
        lstOutput.Items.Add("Name: " & name)
        lstOutput.Items.Add("Address: " & address)
        lstOutput.Items.Add("City: " & zip)
        lstOutput.Items.Add(" ")
        lstOutput.Items.Add("Number of chairs: " & txtChairs.Text)
        lstOutput.Items.Add("Number of sofas: " & txtSofas.Text)
        lstOutput.Items.Add(" ")
        lstOutput.Items.Add(" Price: " & price.ToString("C2"))
        lstOutput.Items.Add("Sales Tax: " & tax.ToString("C2"))
        lstOutput.Items.Add(" ")
        lstOutput.Items.Add("Total Price: " & total.ToString("C2"))

    End Sub

End Class

1 个答案:

答案 0 :(得分:0)

chairQuant和sofaQuant的值在声明之后永远不会被初始化。它们仅作为默认值0传递给TotalCost函数。在将它们传递给此函数之前,需要将它们设置为它们应该的任何值。也许应该将ByRef传递给InputData方法,以便它们可以初始化?