Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. Switch Statement from Hell

Switch Statement from Hell

Scheduled Pinned Locked Moved The Weird and The Wonderful
11 Posts 8 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brady Kelly
    wrote on last edited by
    #1

    Nothing horrible like using enums or flags as case values, no, we preserve the whole JOIN clause, as issued from some vile marriage between combo box and literals. Yes, the strSQLJOIN value is chosen as a SelectedValue of a combo! There are eight cases, this being the last. The first only includes Level1.

                switch (strSQLJOIN)
                {
    

    .
    .
    case "LEFT JOIN Extensions ON CallRecords.Ext_ID = Extensions.Ext_ID LEFT JOIN Level1 ON Extensions.LevUp_ID = Level1.Lev_ID LEFT JOIN Level2 ON Level1.LevUp_ID = Level2.Lev_ID LEFT JOIN Level3 ON Level2.LevUp_ID = Level3.Lev_ID LEFT JOIN Level4 ON Level3.LevUp_ID = Level4.Lev_ID LEFT JOIN Level5 ON Level4.LevUp_ID = Level5.Lev_ID LEFT JOIN Level6 ON Level5.LevUp_ID = Level6.Lev_ID LEFT JOIN Level7 ON Level6.LevUp_ID = Level7.Lev_ID LEFT JOIN Level8 ON Level7.LevUp_ID = Level8.Lev_ID LEFT JOIN CAT ON CallRecords.Cat_ID = CAT.Cat_ID ":
    detailSelectList = "select Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName, ";
    strSQLGROUPandORDER = "GROUP BY Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName ORDER BY Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName;";
    break;

    L J R S S 5 Replies Last reply
    0
    • B Brady Kelly

      Nothing horrible like using enums or flags as case values, no, we preserve the whole JOIN clause, as issued from some vile marriage between combo box and literals. Yes, the strSQLJOIN value is chosen as a SelectedValue of a combo! There are eight cases, this being the last. The first only includes Level1.

                  switch (strSQLJOIN)
                  {
      

      .
      .
      case "LEFT JOIN Extensions ON CallRecords.Ext_ID = Extensions.Ext_ID LEFT JOIN Level1 ON Extensions.LevUp_ID = Level1.Lev_ID LEFT JOIN Level2 ON Level1.LevUp_ID = Level2.Lev_ID LEFT JOIN Level3 ON Level2.LevUp_ID = Level3.Lev_ID LEFT JOIN Level4 ON Level3.LevUp_ID = Level4.Lev_ID LEFT JOIN Level5 ON Level4.LevUp_ID = Level5.Lev_ID LEFT JOIN Level6 ON Level5.LevUp_ID = Level6.Lev_ID LEFT JOIN Level7 ON Level6.LevUp_ID = Level7.Lev_ID LEFT JOIN Level8 ON Level7.LevUp_ID = Level8.Lev_ID LEFT JOIN CAT ON CallRecords.Cat_ID = CAT.Cat_ID ":
      detailSelectList = "select Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName, ";
      strSQLGROUPandORDER = "GROUP BY Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName ORDER BY Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName;";
      break;

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Well, that is what you can get when applying the principles of self-documenting code. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      Avoiding unwanted divs (as in "articles needing approval") with the help of this FireFox add-in


      1 Reply Last reply
      0
      • B Brady Kelly

        Nothing horrible like using enums or flags as case values, no, we preserve the whole JOIN clause, as issued from some vile marriage between combo box and literals. Yes, the strSQLJOIN value is chosen as a SelectedValue of a combo! There are eight cases, this being the last. The first only includes Level1.

                    switch (strSQLJOIN)
                    {
        

        .
        .
        case "LEFT JOIN Extensions ON CallRecords.Ext_ID = Extensions.Ext_ID LEFT JOIN Level1 ON Extensions.LevUp_ID = Level1.Lev_ID LEFT JOIN Level2 ON Level1.LevUp_ID = Level2.Lev_ID LEFT JOIN Level3 ON Level2.LevUp_ID = Level3.Lev_ID LEFT JOIN Level4 ON Level3.LevUp_ID = Level4.Lev_ID LEFT JOIN Level5 ON Level4.LevUp_ID = Level5.Lev_ID LEFT JOIN Level6 ON Level5.LevUp_ID = Level6.Lev_ID LEFT JOIN Level7 ON Level6.LevUp_ID = Level7.Lev_ID LEFT JOIN Level8 ON Level7.LevUp_ID = Level8.Lev_ID LEFT JOIN CAT ON CallRecords.Cat_ID = CAT.Cat_ID ":
        detailSelectList = "select Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName, ";
        strSQLGROUPandORDER = "GROUP BY Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName ORDER BY Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName;";
        break;

        J Offline
        J Offline
        Jeroen De Dauw
        wrote on last edited by
        #3

        *Attempted to write a reply but got a heart attack while having a second look at the code* Cheers :) BN

        GSoC 2009 student for SMW! --- My little forums: http://code.bn2vs.com --- 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!

        B 1 Reply Last reply
        0
        • B Brady Kelly

          Nothing horrible like using enums or flags as case values, no, we preserve the whole JOIN clause, as issued from some vile marriage between combo box and literals. Yes, the strSQLJOIN value is chosen as a SelectedValue of a combo! There are eight cases, this being the last. The first only includes Level1.

                      switch (strSQLJOIN)
                      {
          

          .
          .
          case "LEFT JOIN Extensions ON CallRecords.Ext_ID = Extensions.Ext_ID LEFT JOIN Level1 ON Extensions.LevUp_ID = Level1.Lev_ID LEFT JOIN Level2 ON Level1.LevUp_ID = Level2.Lev_ID LEFT JOIN Level3 ON Level2.LevUp_ID = Level3.Lev_ID LEFT JOIN Level4 ON Level3.LevUp_ID = Level4.Lev_ID LEFT JOIN Level5 ON Level4.LevUp_ID = Level5.Lev_ID LEFT JOIN Level6 ON Level5.LevUp_ID = Level6.Lev_ID LEFT JOIN Level7 ON Level6.LevUp_ID = Level7.Lev_ID LEFT JOIN Level8 ON Level7.LevUp_ID = Level8.Lev_ID LEFT JOIN CAT ON CallRecords.Cat_ID = CAT.Cat_ID ":
          detailSelectList = "select Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName, ";
          strSQLGROUPandORDER = "GROUP BY Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName ORDER BY Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName;";
          break;

          R Offline
          R Offline
          ricmil42
          wrote on last edited by
          #4

          Brady Kelly wrote:

          Switch Statement from Hell

          You were NOT exaggerating!

          1 Reply Last reply
          0
          • B Brady Kelly

            Nothing horrible like using enums or flags as case values, no, we preserve the whole JOIN clause, as issued from some vile marriage between combo box and literals. Yes, the strSQLJOIN value is chosen as a SelectedValue of a combo! There are eight cases, this being the last. The first only includes Level1.

                        switch (strSQLJOIN)
                        {
            

            .
            .
            case "LEFT JOIN Extensions ON CallRecords.Ext_ID = Extensions.Ext_ID LEFT JOIN Level1 ON Extensions.LevUp_ID = Level1.Lev_ID LEFT JOIN Level2 ON Level1.LevUp_ID = Level2.Lev_ID LEFT JOIN Level3 ON Level2.LevUp_ID = Level3.Lev_ID LEFT JOIN Level4 ON Level3.LevUp_ID = Level4.Lev_ID LEFT JOIN Level5 ON Level4.LevUp_ID = Level5.Lev_ID LEFT JOIN Level6 ON Level5.LevUp_ID = Level6.Lev_ID LEFT JOIN Level7 ON Level6.LevUp_ID = Level7.Lev_ID LEFT JOIN Level8 ON Level7.LevUp_ID = Level8.Lev_ID LEFT JOIN CAT ON CallRecords.Cat_ID = CAT.Cat_ID ":
            detailSelectList = "select Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName, ";
            strSQLGROUPandORDER = "GROUP BY Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName ORDER BY Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName;";
            break;

            S Offline
            S Offline
            Spunky Coder
            wrote on last edited by
            #5

            Thank God! There are only 8 levels!!

            "Don't worry if it doesn't work right. If everything did, you'd be out of a job." (Mosher's Law of Software Engineering)

            1 Reply Last reply
            0
            • B Brady Kelly

              Nothing horrible like using enums or flags as case values, no, we preserve the whole JOIN clause, as issued from some vile marriage between combo box and literals. Yes, the strSQLJOIN value is chosen as a SelectedValue of a combo! There are eight cases, this being the last. The first only includes Level1.

                          switch (strSQLJOIN)
                          {
              

              .
              .
              case "LEFT JOIN Extensions ON CallRecords.Ext_ID = Extensions.Ext_ID LEFT JOIN Level1 ON Extensions.LevUp_ID = Level1.Lev_ID LEFT JOIN Level2 ON Level1.LevUp_ID = Level2.Lev_ID LEFT JOIN Level3 ON Level2.LevUp_ID = Level3.Lev_ID LEFT JOIN Level4 ON Level3.LevUp_ID = Level4.Lev_ID LEFT JOIN Level5 ON Level4.LevUp_ID = Level5.Lev_ID LEFT JOIN Level6 ON Level5.LevUp_ID = Level6.Lev_ID LEFT JOIN Level7 ON Level6.LevUp_ID = Level7.Lev_ID LEFT JOIN Level8 ON Level7.LevUp_ID = Level8.Lev_ID LEFT JOIN CAT ON CallRecords.Cat_ID = CAT.Cat_ID ":
              detailSelectList = "select Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName, ";
              strSQLGROUPandORDER = "GROUP BY Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName ORDER BY Sites.SiteName, Sites.ReportCentre, Level8.LevelCode, Level8.LevelName;";
              break;

              S Offline
              S Offline
              Super Lloyd
              wrote on last edited by
              #6

              What about the other case statements? I'm curious now!! ;)

              A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

              B 1 Reply Last reply
              0
              • S Super Lloyd

                What about the other case statements? I'm curious now!! ;)

                A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                B Offline
                B Offline
                Brady Kelly
                wrote on last edited by
                #7

                OK, that was the last one, here are the first two.. You should be able to infer the rest.

                                case "LEFT JOIN Extensions ON CallRecords.Ext\_ID = Extensions.Ext\_ID LEFT JOIN Level1 ON Extensions.LevUp\_ID = Level1.Lev\_ID LEFT JOIN CAT ON CallRecords.Cat\_ID = CAT.Cat\_ID ":
                                    strSQL = strSQL + "Sites.SiteName, Sites.ReportCentre, Level1.LevelCode, Level1.LevelName, ";
                                    strSQLGROUPandORDER = "GROUP BY Sites.SiteName, Sites.ReportCentre, Level1.LevelCode, Level1.LevelName ORDER BY Sites.SiteName, Sites.ReportCentre, Level1.LevelCode, Level1.LevelName;";
                                    break;
                
                                case "LEFT JOIN Extensions ON CallRecords.Ext\_ID = Extensions.Ext\_ID LEFT JOIN Level1 ON Extensions.LevUp\_ID = Level1.Lev\_ID LEFT JOIN Level2 ON Level1.LevUp\_ID = Level2.Lev\_ID LEFT JOIN CAT ON CallRecords.Cat\_ID = CAT.Cat\_ID ":
                                    strSQL = strSQL + "Sites.SiteName, Sites.ReportCentre, Level2.LevelCode, Level2.LevelName, ";
                                    strSQLGROUPandORDER = "GROUP BY Sites.SiteName, Sites.ReportCentre, Level2.LevelCode, Level2.LevelName ORDER BY Sites.SiteName, Sites.ReportCentre, Level2.LevelCode, Level2.LevelName;";
                                    break;
                

                You really gotta try harder to keep up with everyone that's not on the short bus with you. - John Simmons / outlaw programmer.

                S 1 Reply Last reply
                0
                • B Brady Kelly

                  OK, that was the last one, here are the first two.. You should be able to infer the rest.

                                  case "LEFT JOIN Extensions ON CallRecords.Ext\_ID = Extensions.Ext\_ID LEFT JOIN Level1 ON Extensions.LevUp\_ID = Level1.Lev\_ID LEFT JOIN CAT ON CallRecords.Cat\_ID = CAT.Cat\_ID ":
                                      strSQL = strSQL + "Sites.SiteName, Sites.ReportCentre, Level1.LevelCode, Level1.LevelName, ";
                                      strSQLGROUPandORDER = "GROUP BY Sites.SiteName, Sites.ReportCentre, Level1.LevelCode, Level1.LevelName ORDER BY Sites.SiteName, Sites.ReportCentre, Level1.LevelCode, Level1.LevelName;";
                                      break;
                  
                                  case "LEFT JOIN Extensions ON CallRecords.Ext\_ID = Extensions.Ext\_ID LEFT JOIN Level1 ON Extensions.LevUp\_ID = Level1.Lev\_ID LEFT JOIN Level2 ON Level1.LevUp\_ID = Level2.Lev\_ID LEFT JOIN CAT ON CallRecords.Cat\_ID = CAT.Cat\_ID ":
                                      strSQL = strSQL + "Sites.SiteName, Sites.ReportCentre, Level2.LevelCode, Level2.LevelName, ";
                                      strSQLGROUPandORDER = "GROUP BY Sites.SiteName, Sites.ReportCentre, Level2.LevelCode, Level2.LevelName ORDER BY Sites.SiteName, Sites.ReportCentre, Level2.LevelCode, Level2.LevelName;";
                                      break;
                  

                  You really gotta try harder to keep up with everyone that's not on the short bus with you. - John Simmons / outlaw programmer.

                  S Offline
                  S Offline
                  Super Lloyd
                  wrote on last edited by
                  #8

                  I see, mmm... Really the original programmer should have foreseen the problem and use Emit to dynamically generate/compile a method for an ever increasing number of case! :cool: :laugh:

                  A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                  OriginalGriffO 1 Reply Last reply
                  0
                  • S Super Lloyd

                    I see, mmm... Really the original programmer should have foreseen the problem and use Emit to dynamically generate/compile a method for an ever increasing number of case! :cool: :laugh:

                    A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                    OriginalGriffO Offline
                    OriginalGriffO Offline
                    OriginalGriff
                    wrote on last edited by
                    #9

                    Super Lloyd wrote:

                    A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....

                    :laugh: :laugh: :laugh: I want to steal your signature!

                    No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

                    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
                    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

                    S 1 Reply Last reply
                    0
                    • OriginalGriffO OriginalGriff

                      Super Lloyd wrote:

                      A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....

                      :laugh: :laugh: :laugh: I want to steal your signature!

                      No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

                      S Offline
                      S Offline
                      Super Lloyd
                      wrote on last edited by
                      #10

                      Ho no... I already stole it from someone else, you can't steal it from me!!! :rolleyes:

                      A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station.... _________________________________________________________ My programs never have bugs, they just develop random features.

                      1 Reply Last reply
                      0
                      • J Jeroen De Dauw

                        *Attempted to write a reply but got a heart attack while having a second look at the code* Cheers :) BN

                        GSoC 2009 student for SMW! --- My little forums: http://code.bn2vs.com --- 70 72 6F 67 72 61 6D 6D 69 6E 67 20 34 20 6C 69 66 65!

                        B Offline
                        B Offline
                        BillW33
                        wrote on last edited by
                        #11

                        I have to say that is the worst switch statement that I have ever seen and I have seen some pretty bad ones :sigh: Bill W

                        Just because the code works, it doesn't mean that it is good code.

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups