-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新手,所以我真的不知道如何工作
你已經有一個狀態類和一個列表(狀態),所以,而不是一個文本框,使用組合的狀態。使用列表作爲數據源。當他們選擇一個國家時,selectditem將擁有您可以在別處使用的名稱,2個字母和稅率 –
Plutonix