Click here to Skip to main content
15,918,343 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
C#
DateTime BorrowDate = DateTime.Now;
     switch (TxtB_Area.Text)
        {
            case "Teachers Reference":
                TxtB_DateReturned.Text = BorrowDate.AddMonths(1).ToShortDateString();
                break;
            case "General Circulation":
                TxtB_DateReturned.Text = BorrowDate.AddDays(1).ToShortDateString();
                break;
            case "Fiction Area":
                TxtB_DateReturned.Text = BorrowDate.AddDays(14).ToShortDateString();
                break;
            case "Multimedia Area":
                MessageBox.Show("This Resource Is For Room or Library Use Only.");
                return;

            case "Comics Area":
                MessageBox.Show("This Resource Is For Room or Library Use Only.");
                return;
        }
Posted
Comments
Adam Zgagacz 24-Mar-15 12:30pm    
Can you elaborate more what is not working? Code you provided looks OK.
Member 11440734 24-Mar-15 12:37pm    
my bad.. cases Teachers Reference and General Circulation aren't providing results and yet case Fiction Area works.
ZurdoDev 24-Mar-15 12:31pm    
Just debug it and you'll see right away what is wrong.
phil.o 24-Mar-15 12:32pm    
Please define "not working".
Member 11440734 24-Mar-15 12:36pm    
my bad.. cases Teachers Reference and General Circulation aren't providing results and yet case Fiction Area works.

1 solution

Its not a good idea to switch cases over a textbox value i.e. in your case TxtB_Area.Text.
Users can enter any text in small / upper cases with any number of spaces.

If the choices are known, use a dropdown.
Additionally, if you must use a textbox then make sure you trim the text and compare against one set of either lower or upper characters.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900