2012-10-17 57 views
0

我想弄清楚如何完成這個程序,並獲得計算顯示在文本框中。這是我到目前爲止的基本代碼將採購價格和贖回率並計算折扣和利率。不知道我在做什麼錯誤。vb.net折扣和利率計劃

Option Strict On 

Public Class _Default 
    Inherits System.Web.UI.Page 

    Dim Purchase As Double 
    Dim Redemption As Double 
    Dim DiscountRate As Double 
    Dim InterestRate As Double 

    Protected Sub btnCalculate_Click(sender As Object, e As EventArgs) _ 
              Handles btnCalculate.Click 

     Double.TryParse(txtPurchase.Text, Purchase) 
     Double.TryParse(txtRedemption.Text, Redemption) 
     Double.TryParse(txtDiscount.Text, DiscountRate) 
     Double.TryParse(txtInterest.Text, InterestRate) 

     If (CDbl(txtPurchase.Text) <= 0) Then 
      MsgBox("Please enter an amount greater than 0") 

     End If 

     If (CDbl(txtRedemption.Text) <= 0) Then 
      MsgBox("Please enter an amount greater than 0") 
     End If 

     DiscountRate = Purchase - Redemption/Purchase 
     InterestRate = Purchase - Redemption/Redemption 

    End Sub 
End Class 
+0

你能解釋一下這個問題? –

+0

@JohnWoo試圖創建一個計算債券折扣和利率的網絡程序。公式正好在購買 - 贖回除以購買和其他方式,但他們沒有顯示出來 – compucrazy

+0

當你在調試器中單步執行時,'DiscountRate'和'InterestRate'在方法的最後得到正確計算? – yhw42

回答

0

當你解析它們時,它們的變量不會自動綁定到控件上。看起來你只需要您的計算後補充一點:

txtDiscount.Text = DiscountRate 
txtInterest.Text = InterestRate 
+0

工作!謝謝! – compucrazy

1

它看起來像您有Operator Precedence一個問題,你需要一些支架。您在第一種情況下通過購買劃分您的贖回,然後從購買中扣除。在第二種情況下,您將通過兌換進行贖回,並從購買中扣除1的結果。嘗試這個。您還需要將結果分配給所顯示的控件。

​​

或者更簡單地說

txtDiscount.Text = ((Purchase - Redemption)/Purchase).ToString 
txtInterest.Text = ((Purchase - Redemption)/Redemption).ToString