CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890

    switch Simple problem ?

    Hi have used a switch the problem
    switch ( sTreeText )
    {
    case "Practice Resource Setup":
    ...........
    break;
    case "Practice Time Setup":
    break;
    case "Quick Buttons":
    break;
    case "Procedure Code Setup":
    break;
    }

    tell me what's wrong ?

    but it says
    Control can't fall through from one case label (first case) to another.

    thanx
    Paresh

  2. #2
    Join Date
    Sep 1999
    Posts
    67
    I think u need a default case


    switch(number)
    {
    case 1:
    .....
    break;
    case 2:
    .....
    break;
    case 3:
    .....
    break;
    default:
    break;
    }


    /Anders

  3. #3
    Join Date
    Sep 2002
    Location
    Philippines
    Posts
    197
    I think you can't do it with string.

    According to MSDN: The expression enclosed in parentheses (after the switch statement), the "controlling expression," must be of an integral type or of a class type for which there is an unambiguous conversion to integral type.

    I guess you should implement it using nested if-then-else statement and strcmp (string compare) function.

    I hope this will help.


    Owen
    "Hhmn... You are damned if you do; and you are damned if you don't." -- bart simpson

  4. #4
    Join Date
    Nov 2002
    Location
    Singapore
    Posts
    1,890
    the strcmp was in VC++/C/C++. I guess you are a core C++ programmer. thanks for help. but in C# it accepts strings also.

  5. #5
    Join Date
    Oct 2001
    Location
    Norway
    Posts
    265

    Re: switch Simple problem ?

    Originally posted by pareshgh
    tell me what's wrong ?
    You are posting incomplete code. See here.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured