子程序数据未显示在列表框中

时间:2014-10-09 19:38:01

标签: vb.net

编辑:所以我设法让GetData函数出现在列表中,但不是ComputeBalance条目。我无法弄清楚我做错了什么。我不确定如何将这些计算中的数据显示在列表框中。

'Get Users Data via Textbox Input'
Private Sub GetData(ByRef parCreditCard As String, ByRef parBalance As Double, ByRef parPurchases As Double, ByRef parPayment As Double)

    parCreditCard = txtCreditCard.Text
    parBalance = txtBalance.Text
    parPurchases = txtPurchases.Text
    parPayment = txtPayment.Text

End Sub
'Compute Balance'
Private Sub ComputeBalance(ByVal parBalance, ByVal parPurchases, ByVal parPayment)
    Dim financeCharge, endBalance, minPayment As Double


    financeCharge = parBalance * 0.015
    endBalance = ((financeCharge) + (parBalance) + (parPurchases)) - (parPayment)

    If parBalance <= 10 Then
        minPayment = endBalance
    Else
        minPayment = (endBalance * 0.05)
    End If
End Sub
'Display Items to list'
Private Sub DisplayStatement(ByVal parCreditCard, ByVal parBalance, ByVal parPurchases, ByVal parPayment, ByVal financeCharge, ByVal endBalance, ByVal minPayment)
    lstStatement.Items.Clear()
    lstStatement.Items.Add("Credit Card Number:" & vbTab & parCreditCard & vbTab)
    lstStatement.Items.Add("Beginning Balance:" & vbTab & parBalance & vbTab)
    lstStatement.Items.Add("Total Purchases:" & vbTab & parPurchases & vbTab)
    lstStatement.Items.Add("Total Payments:" & vbTab & parPayment & vbTab)
    lstStatement.Items.Add("Finance Charges:" & vbTab & financeCharge & vbTab)
    lstStatement.Items.Add("End of Month Balance:" & vbTab & endBalance & vbTab)
    lstStatement.Items.Add("Minimum Payment:" & vbTab & minPayment & vbTab)

End Sub
Private Sub btnCalculate_Click(sender As System.Object, e As System.EventArgs) Handles btnCalculate.Click
    Dim parBalance, parPurchases, parPayment, financeCharge, endBalance, minPayment As Double
    Dim parCreditCard As String
    GetData(parCreditCard, parBalance, parPurchases, parPayment)
    ComputeBalance(endBalance, minPayment, financeCharge)
    DisplayStatement(parCreditCard, parBalance, parPurchases, parPayment, financeCharge, endBalance, minPayment)

End Sub

Private Sub txtCreditCardNumber_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtCreditCard.TextChanged

End Sub

Private Sub txtFirstBalance_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtBalance.TextChanged

End Sub
End Class

编辑2:我设法让它工作,但我确信我做的方式可以用更简单的方式完成,不过这里是我使用的代码:

 Public Class Lab4
 'Get Users Data via Textbox Input'
Public Sub GetData(ByRef parCreditCard As String, ByRef parBalance As Double, ByRef parPurchases As Double, ByRef parPayment As Double)
    parCreditCard = txtCreditCard.Text
    parBalance = txtBalance.Text
    parPurchases = txtPurchases.Text
    parPayment = txtPayment.Text

End Sub

'Compute Balance'
Private Sub ComputeBalance(ByRef parBalance As Double, ByRef parPurchases As Double, ByRef parPayment As Double)
    Dim financeCharge, endBalance, minPayment As String
    parBalance = txtBalance.Text
    parPayment = txtPayment.Text
    parPurchases = txtPurchases.Text
    financeCharge = parBalance * 0.015
    endBalance = ((financeCharge) + (parBalance) + (parPurchases)) - (parPayment)
    If parBalance <= 10 Then
        minPayment = endBalance
    Else
        minPayment = (endBalance * 0.05)
    End If
    txtFinance.Text = financeCharge
    txtEndBalance.Text = endBalance
    txtMinPayment.Text = minPayment
End Sub

'Display Items to list'
Private Sub DisplayStatement(ByVal parCreditCard, ByVal parBalance, ByVal parPurchases, ByVal parPayment, ByVal financeCharge, ByVal endBalance, ByVal minPayment)
    financeCharge = txtFinance.Text
    endBalance = txtEndBalance.Text
    minPayment = txtMinPayment.Text
    lstStatement.Items.Clear()
    lstStatement.Items.Add("Credit Card Number:" & vbTab & parCreditCard & vbTab)
    lstStatement.Items.Add("Beginning Balance:" & vbTab & parBalance & vbTab)
    lstStatement.Items.Add("Total Purchases:" & vbTab & parPurchases & vbTab)
    lstStatement.Items.Add("Total Payments:" & vbTab & parPayment & vbTab)
    lstStatement.Items.Add("Finance Charges:" & vbTab & financeCharge & vbTab)
    lstStatement.Items.Add("Month End Balance:" & vbTab & endBalance & vbTab)
    lstStatement.Items.Add("Minimum Payment:" & vbTab & minPayment & vbTab)
End Sub

Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
    Dim parBalance, parPurchases, parPayment, financeCharge, endBalance, minPayment As Double
    Dim parCreditCard As String
    GetData(parCreditCard, parBalance, parPurchases, parPayment)
    ComputeBalance(parBalance, parPurchases, parPayment)
    DisplayStatement(parCreditCard, parBalance, parPurchases, parPayment, financeCharge, endBalance, minPayment)
End Sub

Private Sub txtCreditCardNumber_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtCreditCard.TextChanged
End Sub

Private Sub txtFirstBalance_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtBalance.TextChanged
End Sub

Private Sub lstStatement_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstStatement.SelectedIndexChanged

End Sub

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

1 个答案:

答案 0 :(得分:0)

首先,financeChargeendBalanceminPayment被声明为Sub ComputeBalance的局部变量。其次,您实际上在financeCharge中将一组名为endBalanceminPaymentSub btnCalculate_Click的变量声明为局部变量。您可能想要为整个Form声明变量(在模块级别)。