2014-11-14 55 views
-1

我真的很高兴我能找人帮忙,但问题是我不是很擅长vb,因为我对它很陌生,任何人都可以为我安排它,因为它需要然后我会看到我能用它做什么。然后,我将能够启动该项目Visual Basic 2010 Express中的状态缩写代码

问题是将状态名称更改为2字母并计算它们的税率。 加州零售客户(州代码=“CA”)收取购买销售税 - 加州税率为10%。来自纽约(州代码=“NY”)和佛罗里达(州代码=“FL”)的零售客户也以5%的税率征税。

下面的代码是我到目前为止

Public Class Form1 

Public Class State 
    Public Sub New(ByVal name As String, ByVal abbr As String, ByVal taxPercent As Decimal) 
    Me.Name = name 
    Me.Abbreviation = abbr 
    Me.TaxPercent = taxPercent 
    End Sub 

    Public Property Name As String 
    Public Property Abbreviation As String 
    Public Property TaxPercent As Decimal 
End Class 

Const U_P_S_DECIMAL As Decimal = 7D 

Const SALES_TAX_RATE_SINGLE As Single = 0.1 '10 Percent Rate 

'declare module-level variables 
Private TotalQuantityInteger As Integer 
Private TotalSalesDecimal As Decimal 

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

Try 
    '5 percent salses tex rate 
    Const SALES_TEX_RATE_SINGLE As Single = 0.05 '5 percent rate 


    Dim states As New List(Of State) 
    states.Add(New State("California", "CA", 10)) 
    states.Add(New State("New York", "NY", 5)) 
    states.Add(New State("Florida", "FL", 5)) 

    For Each state As State In states 
     Console.WriteLine("State: {0} Abbrevation: {1} Tax: {2}%", 
          state.Name, state.Abbreviation, state.TaxPercent) 
    Next 

    'Declare variables 
    Dim SubDecimal, SalesTaxDecimal, TotalDueDecimal, TotalCostDecimal, ShippingCostDecimal As Decimal 
    'Declare variables and convert value from textbox controls to memory 
    Dim PriceDecimal As Decimal = Decimal.Parse(PriceTextBox.Text, Globalization.NumberStyles.Currency) 
    Dim QuantityInteger As Integer = Integer.Parse(QuantityTextBox.Text, Globalization.NumberStyles.Number) 

    'Process - Compute values 
    'Subtotal = price times the quantity of books 
    TotalCostDecimal = PriceDecimal * QuantityInteger 

    'Sales tex = sales tax rate times the subtotal minus discount amount 
    SalesTaxDecimal = Decimal.Round(Convert.ToDecimal(TotalCostDecimal * SALES_TEX_RATE_SINGLE), 2) 

    SubDecimal = SalesTaxDecimal + ShippingCostDecimal 

    'Total due is the subtotal minus discount amount plus sales tex 
    TotalDueDecimal = TotalCostDecimal + SubDecimal 

    If UPSRadioButton.Checked Then 'compute the shipping cost 
     ShippingCostDecimal = U_P_S_DECIMAL * QuantityInteger 
    End If 


    'Output - display output formatted as currency 
    SubtotalTextBox.Text = TotalCostDecimal.ToString("C") 
    TotalDueTextBox.Text = TotalDueDecimal.ToString("C") 
    salestaxTextBox.Text = SalesTaxDecimal.ToString("N") 
    ShippingCostTextBox.Text = ShippingCostDecimal.ToString("N") 

    'Accumulate total sales and total books sold 
    TotalQuantityInteger += QuantityInteger 
    TotalSalesDecimal += TotalDueDecimal 
Catch ex As Exception 

End Try 
End Sub 

我输入我上这里的代码,但我不知道该怎么做,从文本框收集数据时进入状态,使税收能做的事被添加到它。任何帮助将不胜感激。 VB新手,所以我真的不知道如何工作

+1

你已经有一个状态类和一个列表(状态),所以,而不是一个文本框,使用组合的状态。使用列表作为数据源。当他们选择一个国家时,selectditem将拥有您可以在别处使用的名称,2个字母和税率 – Plutonix

回答

0
For Each state As State In states 
    If state.name = TextBox.text then 
    'add your code here, you get the tax Rate with state.TaxPercent 
    '... 
    exit for 
Next