Im new to C# and having trouble with this code: I have a combo box on a form optypeCB and when a particular type is picked(Draw,Form,Pierce,Trim) I would like a numerical value assigned to a text box designhrsTB. My code is as follows but it does not work can anyone help me. Thanks in advance

        optypCB.Text ;
        switch(int);
        {
            case "Draw":
                designhrsTB = 80;
            case  "Form":
                designhrsTB = 120;
            case "Pierce":
            designhrsTB =120;
            case "Trim":
            designhrsTB =160;
        }

Recommended Answers

All 9 Replies

switch(int); What is int? Remove the ; after it to begin with.
Where is default? Where is break?

I thought i had to call it an integer? Not sure where break or default should be.

The switch statement is similar for all languages. I'm trying not to be rude but saying "Im new to C#" and put a ; after switch() is more like "I'm new to programming altogether".

If this is the case, I'd suggest reading on line about switch and other language syntax.

any suggestions for a good source to read. I have read a few but still very fuzzy

You can switch directly on the string, but make sure you won't have a case-sensitive issue. More can be read at: http://blogs.msdn.com/brada/archive/2003/08/14/50227.aspx

switch(optypCB.Text)
{
case "Draw":
designhrsTB = 80; break;
case "Form":
designhrsTB = 120; break;
case "Pierce":
designhrsTB =120; break;
case "Trim":
designhrsTB =160; break;
default:
throw new Exception("Unknown selection");
}

Yeah, sknake, you are very good. But the point was to let him figure that out by himself...

I have gotten the sense of a lot of users on this forum sharing the same mindset? Why is that :(

We posted at the same time before i saw you provided articles, but I figured I would help him out since he was getting blasted about his misuse of a semi colon.

I have gotten the sense of a lot of users on this forum sharing the same mindset? Why is that :(

I agree, it seems like somehow the mindset of figuring out how to write code on your own has been transformed in this thread into the mindset of knowing all the features of a language and figuring out how it works, all while somehow being able to distinguish between good sources of information and bad sources of information without having the knowledge needed to do so.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.