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. Now this is bad....

Now this is bad....

Scheduled Pinned Locked Moved The Weird and The Wonderful
21 Posts 18 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.
  • E emartinho

    EDIT: This is LOOOONG. Sorry. :D The following code is used to create "WHERE" clause criteria, for all possible cominations of 8 "class" parameters if the "group_a" parameter is passed with a value. I know there's a better way of doing this, but I can't be bothered to unravel this convoluted piece of code! :laugh:

    Function grpStatement(group_a As String, class_aa As String, class_ab As String, class_ac As String, _
    class_ad As String, class_ae As String, class_af As String, class_ag As String, _
    class_ah As String, classCondition_a As String) As String

    Dim groupCondition_a As String

    If group\_a <> "" Then
        If class\_aa <> "" Then
            classCondition\_a = classCondition\_a & "'" & class\_aa & " %'"
            If class\_ab <> "" Then
                classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ab & " %'"
                If class\_ac <> "" Then
                    classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ac & " %'"
                    If class\_ad <> "" Then
                        classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ad & " %'"
                        If class\_ae <> "" Then
                            classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ae & " %'"
                            If class\_af <> "" Then
                                classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_af & " %'"
                                If class\_ag <> "" Then
                                    classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ag & " %'"
                                    If class\_ah <> "" Then
                                        classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ah & " %'"
                                    End If
                                ElseIf class\_ah <> "" Then
                                    classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ah & " %'"
                                End If
                            ElseIf class\_ag <> "" Then
                                classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ag & " %'"
                                If class\_ah <> "" Then
    
    B Offline
    B Offline
    BillW33
    wrote on last edited by
    #12

    That is pretty horible. The only good thing about that block of code is that it is neatly formated. ;) :sigh: :laugh:

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

    E 1 Reply Last reply
    0
    • B BillW33

      That is pretty horible. The only good thing about that block of code is that it is neatly formated. ;) :sigh: :laugh:

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

      E Offline
      E Offline
      emartinho
      wrote on last edited by
      #13

      I was the one that formatted it! :laugh: You should have seen what it looked like before. I won't post it because it's way too large, but trust me, it was pretty bad! :D

      B 1 Reply Last reply
      0
      • L Luc Pattyn

        Don't feel too bad about it, yours was pretty horrible too. :)

        Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.

        A Offline
        A Offline
        AspDotNetDev
        wrote on last edited by
        #14

        Thanks... that's, uh, comforting. :rolleyes:

        Chris Maunder:

        Fixign now.

        1 Reply Last reply
        0
        • E emartinho

          I was the one that formatted it! :laugh: You should have seen what it looked like before. I won't post it because it's way too large, but trust me, it was pretty bad! :D

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

          I am not at all surprised that the original code was not nicely formated. Which means that the original code had no redeeming features. X|

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

          1 Reply Last reply
          0
          • B Bernhard Hiller

            That guy tricked you. He wrote a code generator (which he hides from you, and the boss) to generate such long lines of code, and thus he earns lots of money since he gets paid for lines of code.

            W Offline
            W Offline
            walterhevedeich
            wrote on last edited by
            #16

            Dirty Consultant Trick # 8?[^] :laugh: :laugh: :laugh:

            Ignorance of the ability brings disability.

            1 Reply Last reply
            0
            • E emartinho

              EDIT: This is LOOOONG. Sorry. :D The following code is used to create "WHERE" clause criteria, for all possible cominations of 8 "class" parameters if the "group_a" parameter is passed with a value. I know there's a better way of doing this, but I can't be bothered to unravel this convoluted piece of code! :laugh:

              Function grpStatement(group_a As String, class_aa As String, class_ab As String, class_ac As String, _
              class_ad As String, class_ae As String, class_af As String, class_ag As String, _
              class_ah As String, classCondition_a As String) As String

              Dim groupCondition_a As String

              If group\_a <> "" Then
                  If class\_aa <> "" Then
                      classCondition\_a = classCondition\_a & "'" & class\_aa & " %'"
                      If class\_ab <> "" Then
                          classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ab & " %'"
                          If class\_ac <> "" Then
                              classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ac & " %'"
                              If class\_ad <> "" Then
                                  classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ad & " %'"
                                  If class\_ae <> "" Then
                                      classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ae & " %'"
                                      If class\_af <> "" Then
                                          classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_af & " %'"
                                          If class\_ag <> "" Then
                                              classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ag & " %'"
                                              If class\_ah <> "" Then
                                                  classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ah & " %'"
                                              End If
                                          ElseIf class\_ah <> "" Then
                                              classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ah & " %'"
                                          End If
                                      ElseIf class\_ag <> "" Then
                                          classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ag & " %'"
                                          If class\_ah <> "" Then
              
              R Offline
              R Offline
              Richard A Dalton
              wrote on last edited by
              #17

              Eeeegads! This code is why code reviews were invented. That programmer should be forced to keep working on that until it's fixed, that way you at least contain them and stop them doing this elsewhere. If they haven't fixed it after a week, fire their ass. Whoever the developers were that let it through a code review...Fire their asses too. Of course I jest. There wasn't a code review, there never is in these situations. So fire whoever is responsible for ensuring there are code reviews. If nobody is responsible for ensuring there are code reviews, fire the person responsible for ensuring that there is a person responsible for ensuring that there are code reviews. When you've recursively made your way to the top of the Org Chart and fired everyone and the company no longer exists, this mess of code will have served it's purpose. -Rd

              Hit any user to continue.

              1 Reply Last reply
              0
              • E emartinho

                EDIT: This is LOOOONG. Sorry. :D The following code is used to create "WHERE" clause criteria, for all possible cominations of 8 "class" parameters if the "group_a" parameter is passed with a value. I know there's a better way of doing this, but I can't be bothered to unravel this convoluted piece of code! :laugh:

                Function grpStatement(group_a As String, class_aa As String, class_ab As String, class_ac As String, _
                class_ad As String, class_ae As String, class_af As String, class_ag As String, _
                class_ah As String, classCondition_a As String) As String

                Dim groupCondition_a As String

                If group\_a <> "" Then
                    If class\_aa <> "" Then
                        classCondition\_a = classCondition\_a & "'" & class\_aa & " %'"
                        If class\_ab <> "" Then
                            classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ab & " %'"
                            If class\_ac <> "" Then
                                classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ac & " %'"
                                If class\_ad <> "" Then
                                    classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ad & " %'"
                                    If class\_ae <> "" Then
                                        classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ae & " %'"
                                        If class\_af <> "" Then
                                            classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_af & " %'"
                                            If class\_ag <> "" Then
                                                classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ag & " %'"
                                                If class\_ah <> "" Then
                                                    classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ah & " %'"
                                                End If
                                            ElseIf class\_ah <> "" Then
                                                classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ah & " %'"
                                            End If
                                        ElseIf class\_ag <> "" Then
                                            classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ag & " %'"
                                            If class\_ah <> "" Then
                
                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #18

                ... where they breed such ingenious people? I have a similar thing here. Thousands of lines in one (static) method which are supposed to generate each and every database query the entire application may need. A nightnare to debug...

                "I just exchanged opinions with my boss. I went in with mine and came out with his." - me, 2011 ---
                I am endeavoring, Madam, to construct a mnemonic memory circuit using stone knives and bearskins - Mr. Spock 1935 and me 2011

                1 Reply Last reply
                0
                • E emartinho

                  EDIT: This is LOOOONG. Sorry. :D The following code is used to create "WHERE" clause criteria, for all possible cominations of 8 "class" parameters if the "group_a" parameter is passed with a value. I know there's a better way of doing this, but I can't be bothered to unravel this convoluted piece of code! :laugh:

                  Function grpStatement(group_a As String, class_aa As String, class_ab As String, class_ac As String, _
                  class_ad As String, class_ae As String, class_af As String, class_ag As String, _
                  class_ah As String, classCondition_a As String) As String

                  Dim groupCondition_a As String

                  If group\_a <> "" Then
                      If class\_aa <> "" Then
                          classCondition\_a = classCondition\_a & "'" & class\_aa & " %'"
                          If class\_ab <> "" Then
                              classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ab & " %'"
                              If class\_ac <> "" Then
                                  classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ac & " %'"
                                  If class\_ad <> "" Then
                                      classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ad & " %'"
                                      If class\_ae <> "" Then
                                          classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ae & " %'"
                                          If class\_af <> "" Then
                                              classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_af & " %'"
                                              If class\_ag <> "" Then
                                                  classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ag & " %'"
                                                  If class\_ah <> "" Then
                                                      classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ah & " %'"
                                                  End If
                                              ElseIf class\_ah <> "" Then
                                                  classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ah & " %'"
                                              End If
                                          ElseIf class\_ag <> "" Then
                                              classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ag & " %'"
                                              If class\_ah <> "" Then
                  
                  V Offline
                  V Offline
                  Vladimir Svyatski
                  wrote on last edited by
                  #19

                  Where did you get this stuff? :wtf: Didn't teachers in university/college tell that you need to split a job into smaller chunks like subfunctions? :)

                  1 Reply Last reply
                  0
                  • E emartinho

                    EDIT: This is LOOOONG. Sorry. :D The following code is used to create "WHERE" clause criteria, for all possible cominations of 8 "class" parameters if the "group_a" parameter is passed with a value. I know there's a better way of doing this, but I can't be bothered to unravel this convoluted piece of code! :laugh:

                    Function grpStatement(group_a As String, class_aa As String, class_ab As String, class_ac As String, _
                    class_ad As String, class_ae As String, class_af As String, class_ag As String, _
                    class_ah As String, classCondition_a As String) As String

                    Dim groupCondition_a As String

                    If group\_a <> "" Then
                        If class\_aa <> "" Then
                            classCondition\_a = classCondition\_a & "'" & class\_aa & " %'"
                            If class\_ab <> "" Then
                                classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ab & " %'"
                                If class\_ac <> "" Then
                                    classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ac & " %'"
                                    If class\_ad <> "" Then
                                        classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ad & " %'"
                                        If class\_ae <> "" Then
                                            classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ae & " %'"
                                            If class\_af <> "" Then
                                                classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_af & " %'"
                                                If class\_ag <> "" Then
                                                    classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ag & " %'"
                                                    If class\_ah <> "" Then
                                                        classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ah & " %'"
                                                    End If
                                                ElseIf class\_ah <> "" Then
                                                    classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ah & " %'"
                                                End If
                                            ElseIf class\_ag <> "" Then
                                                classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ag & " %'"
                                                If class\_ah <> "" Then
                    
                    A Offline
                    A Offline
                    Albert Holguin
                    wrote on last edited by
                    #20

                    wow :omg: :wtf:

                    1 Reply Last reply
                    0
                    • E emartinho

                      EDIT: This is LOOOONG. Sorry. :D The following code is used to create "WHERE" clause criteria, for all possible cominations of 8 "class" parameters if the "group_a" parameter is passed with a value. I know there's a better way of doing this, but I can't be bothered to unravel this convoluted piece of code! :laugh:

                      Function grpStatement(group_a As String, class_aa As String, class_ab As String, class_ac As String, _
                      class_ad As String, class_ae As String, class_af As String, class_ag As String, _
                      class_ah As String, classCondition_a As String) As String

                      Dim groupCondition_a As String

                      If group\_a <> "" Then
                          If class\_aa <> "" Then
                              classCondition\_a = classCondition\_a & "'" & class\_aa & " %'"
                              If class\_ab <> "" Then
                                  classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ab & " %'"
                                  If class\_ac <> "" Then
                                      classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ac & " %'"
                                      If class\_ad <> "" Then
                                          classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ad & " %'"
                                          If class\_ae <> "" Then
                                              classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ae & " %'"
                                              If class\_af <> "" Then
                                                  classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_af & " %'"
                                                  If class\_ag <> "" Then
                                                      classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ag & " %'"
                                                      If class\_ah <> "" Then
                                                          classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ah & " %'"
                                                      End If
                                                  ElseIf class\_ah <> "" Then
                                                      classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ah & " %'"
                                                  End If
                                              ElseIf class\_ag <> "" Then
                                                  classCondition\_a = classCondition\_a & " OR Level4 LIKE '" & class\_ag & " %'"
                                                  If class\_ah <> "" Then
                      
                      R Offline
                      R Offline
                      Ravi Sant
                      wrote on last edited by
                      #21

                      :wtf: He must be suggested to join anti-if campaign.

                      // ♫ 99 little bugs in the code, // 99 bugs in the code // We fix a bug, compile it again // 101 little bugs in the 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