简体   繁体   English

Visual Basic状态税计算器

[英]Visual Basic state tax calculator

Im working on a visual basic project creating a tax calculator. 我正在从事视觉基础项目的创建税收计算器的工作。 Right now, i have two arrays, one for the states and one for the tax rates. 现在,我有两个数组,一个用于州,一个用于税率。 States starting with AL have the same tax rate of 2%, MP 3.5%, and RW 4%. 以AL开头的州的税率分别为2%,MP 3.5%和RW 4%。 Right now this is what the two arrays look like: 现在,这是两个数组的样子:

 Dim states() As String = {"Alabama", "Alaska", "Arizona", "Arkansas", 
   "California", "Colorado", "Connecticut", "Delaware", "Florida", 
    "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", 
    "Kentucky", "Louisiana", "Maine", "Maryland", "Massachusetts", 
    "Michigan", "Minnesota", "Mississippi", "Missouri", "Montana", 
    "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico", "New 
    York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", 
    "Pennsylvania", "Rhode Island", "South Carolina", "South Dakota", 
    "Tennessee", "Texas", "Utah", "Vermont", "Virginia", "Washington", 
    "West Virginia", "Wisconsin", "Wyoming"} 

    Dim statetax() As Double = {0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 
    0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.02, 0.035, 
    0.035, 0.035, 0.035, 0.035, 0.035, 0.035, 0.035, 0.035, 0.035, 0.035, 
    0.035, 0.035, 0.035, 0.035, 0.035, 0.035, 0.035, 0.035, 0.035, 0.035, 
    0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04}

Then, to calculate the state tax I have a bunch of If selectstate starts with "a" "b" "c" or "d" then totalstatetax = statetax(0) * income 然后,要计算州税,我有一堆如果selectstate以“ a”,“ b”,“ c”或“ d”开头,则totalstatetax = statetax(0)*收入

I was wondering if there was a simplified version, or a way or creating an index that would allow the states and state tax to coincide. 我想知道是否有一个简化的版本,或者是一种方法或创建一个允许州与州税重合的索引。 any help is appreciated. 任何帮助表示赞赏。 thanks! 谢谢!

Dictionary could be right tool for the job 字典可能是工作的正确工具

var stateTaxes = new Dictionary<string, decimal>
{
    { "Alabama", 0.02m },
    { "Maine", 0.035m },
    // other states
}

var alabamaTaxAmount = income * stateTaxes["Alabama"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM