Visual Basic 2010 Express中的状态缩写代码

时间:2014-11-14 11:23:42

标签: vb.net

我真的很高兴有人帮忙解决这个问题,但问题是vb并不是很好,因为我很新,有人可以为我安排,因为它需要的时候我会看到我能做什么做它。然后我将能够启动项目

问题是将状态名称更改为2个字母并计算它们的税率。 加利福尼亚零售客户(州代码=“CA”)按购买征收销售税 - 加州税率为10%。来自纽约(州代码=“纽约州”)和佛罗里达州(州代码=“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 个答案:

答案 0 :(得分: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