Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5953433
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:49:31+00:00 2026-05-22T17:49:31+00:00

Okay So what i am having trouble with is these lines of code below.

  • 0

Okay So what i am having trouble with is these lines of code below.

 if (textBox1.Text == "Alabama" || textBox1.Text == "alabama")
    {
        StateTax = 0.0570;
    }if (textBox1.Text == "Alaska" || textBox1.Text == "alaska")
    {
        StateTax = 0.1167;
    }if (textBox1.Text == "Arizona" || textBox1.Text == "arizona")
    {
        StateTax = 0.0592;
    }if (textBox1.Text == "Arkansas" || textBox1.Text == "arkansas")
    {
        StateTax = 0.0835;
    }if (textBox1.Text == "California" || textBox1.Text == "california")
    {
        StateTax = 0.0739;
    }if (textBox1.Text == "Colorado" || textBox1.Text == "colorado")
    {
        StateTax = 0.0272;
    }if (textBox1.Text == "Connecticut" || textBox1.Text == "connecticut")
    {
        StateTax = 0.0654;
    }if (textBox1.Text == "Deleware" || textBox1.Text == "deleware")
    {
        StateTax = 0.0825;
    }if (textBox1.Text == "Florida" || textBox1.Text == "flordia")
    {
        StateTax = 0.0503;
    }if (textBox1.Text == "Georgia" || textBox1.Text == "georgia")
    {
        StateTax = 0.0562;
    }if (textBox1.Text == "Hawaii" || textBox1.Text == "hawaii")
    {
        StateTax = 0.0985;
    }if (textBox1.Text == "Idaho" || textBox1.Text == "idaho")
    {
        StateTax = 0.0736;
    }if (textBox1.Text == "Illinois" || textBox1.Text == "illinois")
    {
        StateTax = 0.0562;
    }if (textBox1.Text == "Indiana" || textBox1.Text == "indiana")
    {
        StateTax = 0.0648;
    }if (textBox1.Text == "Iowa" || textBox1.Text == "iowa")
    {
        StateTax = 0.0591;
    }if (textBox1.Text == "Kansas" || textBox1.Text == "kansas")
    {
        StateTax = 0.0654;
    }if (textBox1.Text == "Kentucky" || textBox1.Text == "kentucky")
    {
        StateTax = 0.0734;
    }if (textBox1.Text == "Louisiana" || textBox1.Text == "louisiana")
    {
        StateTax = 0.0685;
    }if (textBox1.Text == "Maine" || textBox1.Text == "maine")
    {
        StateTax = 0.0770;
    }if (textBox1.Text == "Maryland" || textBox1.Text == "maryland")
    {
        StateTax = 0.0559;
    }if (textBox1.Text == "Massachusetts" || textBox1.Text == "massachusetts")
    {
        StateTax = 0.0630;
    }if (textBox1.Text == "Michigan" || textBox1.Text == "Michigan")
    {
        StateTax = 0.0672;
    }if (textBox1.Text == "Minnesota" || textBox1.Text == "minnesota")
    {
        StateTax = 0.0802;
    }if (textBox1.Text == "Mississippi" || textBox1.Text == "mississippi")
    {
        StateTax = 0.0740;
    }if (textBox1.Text == "Missouri" || textBox1.Text == "missouri")
    {
        StateTax = 0.0517;
    }if (textBox1.Text == "Montana" || textBox1.Text == "montana")
    {
        StateTax = 0.0708;
    }if (textBox1.Text == "Nebraska" || textBox1.Text == "nebraska")
    {
        StateTax = 0.0610;
    }if (textBox1.Text == "Nevada" || textBox1.Text == "nevada")
    {
        StateTax = 0.0612;
    }if (textBox1.Text == "New Hampshire" || textBox1.Text == "new hampshire")
    {
        StateTax = 0.0387;
    }if (textBox1.Text == "New Jersey" || textBox1.Text == "new jersey")
    {
        StateTax = 0.0661;
    }if (textBox1.Text == "New Mexico" || textBox1.Text == "new mexico")
    {
        StateTax = 0.0826;
    }if (textBox1.Text == "New York" || textBox1.Text == "new york")
    {
        StateTax = 0.0676;
    }if (textBox1.Text == "North Carolina" || textBox1.Text == "north carolina")
    {
        StateTax = 0.0726;
    }if (textBox1.Text == "North Dakota" || textBox1.Text == "north dakota")
    {
        StateTax = 0.0711;
    }if (textBox1.Text == "Ohio" || textBox1.Text == "Ohio")
    {
        StateTax = 0.0609;
    }if (textBox1.Text == "Oklahoma" || textBox1.Text == "oklahoma")
    {
        StateTax = 0.0621;
    }if (textBox1.Text == "Oregon" || textBox1.Text == "oregon")
    {
        StateTax = 0.0576;
    }if (textBox1.Text == "Pennsylvania" || textBox1.Text == "pennsylvania")
    {
        StateTax = 0.0617;
    }if (textBox1.Text == "Rhode Island" || textBox1.Text == "rhode island")
    {
        StateTax = 0.0640;
    }if (textBox1.Text == "South Carolina" || textBox1.Text == "south carolina")
    {
        StateTax = 0.0619;
    }if (textBox1.Text == "South Dakota" || textBox1.Text == "south dakota")
    {
        StateTax = 0.0423;
    }if (textBox1.Text == "Tennessee" || textBox1.Text == "tennessee")
    {
        StateTax = 0.0539;
    }if (textBox1.Text == "Texas" || textBox1.Text == "texas")
    {
        StateTax = 0.0438;
    }if (textBox1.Text == "Utah" || textBox1.Text == "utah")
    {
        StateTax = 0.0728;
    }if (textBox1.Text == "Vermont" || textBox1.Text == "vermont")
    {
        StateTax = 0.1060;
    }if (textBox1.Text == "Virginia" || textBox1.Text == "virginia")
    {
        StateTax = 0.0563;
    }if (textBox1.Text == "Washington" || textBox1.Text == "washington")
    {
        StateTax = 0.0648;
    }if (textBox1.Text == "West Virginia" || textBox1.Text == "west virginia")
    {
        StateTax = 0.0834;
    }if (textBox1.Text == "Wisconsin" || textBox1.Text == "wisconsin")
    {
        StateTax = 0.0693;
    }if (textBox1.Text == "Wyoming" || textBox1.Text == "wyoming")
    {
        StateTax = 0.0778;
    } if (textBox1.Text == "" || textBox1.Text == "")
    {
        string messageBoxText = "Their is No State Entered into the first pages  State Textbox";
        MessageBox.Show(messageBoxText);
        return;

    }

What I’m trying to do is make this textbox1 searchable so that i can have it go through and only allow one of the states to be entered in it, if not then an error message will show up.
Now i know this can be done and sense i haven’t found any info on it I’m guessing its quit easy. but yet i need help haha
So if someone could help me with this that would be lovely.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:49:32+00:00Added an answer on May 22, 2026 at 5:49 pm

    I hate to come right out and say it, but since this is a teaching website, I will: your current solution is ugly. At a minimum, you should provide some sort of lookup table for yourself, whether it be a dictionary, an XML file, or database table, you shouldn’t have to duplicate that many lines of code. Something like this immediately comes to mind and would greatly simplify your code.

    var rates = new Dictionary<string, decimal> 
    {
        { "alabama", 0.0570 },
        { "alaska", 0.1167 },
        ...
        { "wyoming", 0.0778 }
    }
    

    With this structure, you can start solving the problems you’re looking to solve. For example, looking up the rate becomes trivial:

    string stateKey = textbox1.Text.Trim().ToLower();
    
    if (rates.ContainsKey(stateKey))
    {
        return rates[stateKey];
    } 
    else 
    {
        throw new Exception("Missing rate for state " + stateKey);
    }
    

    And at the same time, I’ve limited what is input into the textbox using the keys in the rate dictionary as your set of possible values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I am having trouble with the following piece of code (in a header
Okay, these two related questions are in reference to Railscast #21 : I'm having
Okay, we know that the following two lines are equivalent - (0 == i)
I'm having trouble understanding why arrays in C# are covariant and what benefits this
Okay, I've looked all over the internet for a good solution to get PHP
Okay, so I'm running a small test webserver on my private network. I've got
Okay so im working on this php image upload system but for some reason
Okay, here's the scenario. I have a utility that processes tons of records, and
Okay, I've seen but haven't programmed in C# before. You can assume I'm competent
Okay, so this probably sounds terribly nefarious, but I need such capabilities for my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.