VB at it's Best.



  • About 4 months ago the place where I work (I won't mention names) fired a programmer and at the time I didn't really know why but they gave me most of his work.  About a month in I was asked to fix one of the functions he wrote that have to do with Parsing XML and deleting nodes.  (Don't ask me why they do this in vb and not XSL, that's the first WTF).  Anyway so I am steping through the code and I come to this For statement with a case statement in the body of the loop.  I swear to you this is real code.   

     

    For i = 1 To 20 '19
            Select Case i
                Case 1 'Operator
                    Set mobjNodeRIList = mobjDOM.selectNodes("//OPERATOR[@CID=24797 and @ISDELETED!='TRUE' and @IsNew='True' and ATTRIBUTE[@CID='884' and @VALUE='No']]")
                    strLabel = "Driver Added:"
                    blnInclDriver = True
                Case 2 'IsNew="False" IsDirty="True">
                    Set mobjNodeRIList = mobjDOM.selectNodes("//OPERATOR[@CID=24797 and @ISDELETED!='TRUE' and @IsNew='False' and @IsDirty='True' and ATTRIBUTE[@CID='884' and @VALUE='No']]")
                    strLabel = "Driver Modified:"
                    blnInclDriver = True
                Case 3
                    Set mobjNodeRIList = mobjDOM.selectNodes("//OPERATOR[@CID=24797 and @ISDELETED='TRUE' and ATTRIBUTE[@CID='884' and @VALUE='No']]")
                    strLabel = "Driver Deleted:"
                    blnInclDriver = True
                Case 4 'Excluded Driver
                    Set mobjNodeRIList = mobjDOM.selectNodes("//OPERATOR[@CID=24797 and @ISDELETED!='TRUE' and @IsNew='True' and ATTRIBUTE[@CID='884' and @VALUE='Yes']]")
                    strLabel = "Excluded Driver Added:"
                    blnInclDriver = True
                Case 5
                    Set mobjNodeRIList = mobjDOM.selectNodes("//OPERATOR[@CID=24797 and @ISDELETED!='TRUE' and @IsNew='False' and @IsDirty='True' and ATTRIBUTE[@CID='884' and @VALUE='Yes']]")
                    strLabel = "Excluded Driver Modified:"
                    blnInclDriver = True
                Case 6
                    Set mobjNodeRIList = mobjDOM.selectNodes("//OPERATOR[@CID=24797 and @ISDELETED='TRUE' and ATTRIBUTE[@CID='884' and @VALUE='Yes']]")
                    strLabel = "Excluded Driver Deleted:"
                    blnInclDriver = True
                Case 7 'Vehicle
                    Set mobjNodeRIList = mobjDOM.selectNodes("//RISKITEMTYPE[@CID=24710 and @ISDELETED!='TRUE' and @IsNew='True']")
                    strLabel = "Vehicle Added:"
                    blnInclVehicle = True
                Case 8
                    Set mobjNodeRIList = mobjDOM.selectNodes("//RISKITEMTYPE[@CID=24710 and @ISDELETED!='TRUE' and @IsNew='False' and @IsDirty='True']")
                    strLabel = "Vehicle Modified:"
                    blnInclVehicle = True
                Case 9
                    Set mobjNodeRIList = mobjDOM.selectNodes("//RISKITEMTYPE[@CID=24710 and @ISDELETED='TRUE']")
                    strLabel = "Vehicle Deleted:"
                    blnInclVehicle = True
                Case 10 'Additional Insured
                    Set mobjNodeRIList = mobjDOM.selectNodes("//ADDITIONALINSURED[@CID=947 and @ISDELETED!='TRUE' and @IsNew='True']")
                    strLabel = "Additional Insured Added:"
                    blnInclAddiIns = True
                Case 11
                    Set mobjNodeRIList = mobjDOM.selectNodes("//ADDITIONALINSURED[@CID=947 and @ISDELETED!='TRUE' and @IsNew='False' and @IsDirty='True']")
                    strLabel = "Additional Insured Modified:"
                    blnInclAddiIns = True
                Case 12
                    Set mobjNodeRIList = mobjDOM.selectNodes("//ADDITIONALINSURED[@CID=947 and @ISDELETED='TRUE']")
                    strLabel = "Additional Insured Deleted:"
                    blnInclAddiIns = True
                Case 13 'AI\LossPayee
                    Set mobjNodeRIList = mobjDOM.selectNodes("//ADDITIONALINTEREST[@CID=1931 and @ISDELETED!='TRUE' and @IsNew='True']")
                    strLabel = "Additional Interest/Loss Payee Added:"
                    blnInclLossPayee = True
                Case 14
                    Set mobjNodeRIList = mobjDOM.selectNodes("//ADDITIONALINTEREST[@CID=1931 and @ISDELETED!='TRUE' and @IsNew='False' and @IsDirty='True']")
                    strLabel = "Additional Interest/Loss Payee Modified:"
                    blnInclLossPayee = True
                Case 15
                    Set mobjNodeRIList = mobjDOM.selectNodes("//ADDITIONALINTEREST[@CID=1931 and @ISDELETED='TRUE']")
                    strLabel = "Additional Interest/Loss Payee Deleted:"
                    blnInclLossPayee = True
                Case 16 'Location
                    Set mobjNodeRIList = mobjDOM.selectNodes("//LOCATION[@CID=789 and @ISDELETED!='TRUE' and @IsNew='True']")
                    strLabel = "Garaging Location Added:"
                    blnInclLocation = True
                Case 17
                    Set mobjNodeRIList = mobjDOM.selectNodes("//LOCATION[@CID=789 and @ISDELETED!='TRUE' and @IsNew='False' and @IsDirty='True']")
                    strLabel = "Garaging Location Modified:"
                    blnInclLocation = True
                Case 18
                    Set mobjNodeRIList = mobjDOM.selectNodes("//LOCATION[@CID=789 and @ISDELETED='TRUE']")
                    strLabel = "Garaging Location Deleted:"
                    blnInclLocation = True
                Case 19 'Attribute Modified (NO NEW/NO DELETED becuase can't add/delete)
                    'TODO: Set tempDOM = mobjDOM at beginig of form
                    '      Remove each test case nodes from tempDOM (new func())
                    '      Set mobjNodeRIList = tempDOM.selectNodes("//ATTRIBUTE[@IsChanged='True']")
                    'Set mobjNodeRIList = mobjDOM.selectNodes("//ATTRIBUTE[@IsDirty='True']")
                    Set mobjNodeRIList = mobjDOM.selectNodes("PROGRAM/ATTRIBUTE[@IsChanged='True']")
                    strLabel = "Attributes Modified:"
                    blnInclAttribute = True
                Case 20
                    'If there is NO change, print empty form???
                    If Not blnFormLoaded Then
                        Set mobjNodeRIList = mobjDOM.selectNodes("PROGRAM[@CID=24709]")
                    End If
                    'strLabel = ""
                    'blnInclLocation = True
            End Select
    Next i

     

     

    wtf?  Why did he get fired?  Doesn't everyone code like that?



  • Hard to believe, but the for-case-loop is an antipattern that is much more common than any sane person would expect.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.