Posts Tagged ‘.NET’

Saddest Code of the Week

Tuesday, April 28th, 2009

I’m helping a client debug a legacy application and found this wonderful piece of code. The worst part is that it wasn’t written in 1980. This is from a .NET application (not VB6), and it has made me very sad.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
        Public Overridable Sub page_init()
            Dim num3 As Integer
            Dim exception As Exception
            Dim num4 As Integer
            Dim num5 As Integer
            Try 
            Label_0000:
                num3 = 0
                Me.whichlevel(0) = "System User"
            Label_0010:
                num3 = 1
                Me.whichlevel(1) = "Administrator"
            Label_0020:
                num3 = 2
                Me.usrid = Me.getcookie("xlaANLadmin", "userid")
            Label_0039:
                num3 = 3
                Me.connectionstr = ConfigurationSettings.AppSettings.Item("xlaANLconnectionstr")
            Label_0051:
                num3 = 4
                If (StringType.StrCmp(Me.Request.QueryString.Item("qut"), "", False) = 0) Then
                    goto Label_02AB
                End If
            Label_007A:
                ProjectData.ClearProjectError
                num5 = 1
            Label_0082:
                num3 = 6
                Dim str3 As String = Strings.UCase(Strings.Replace(Me.appsettings.xla_id, "-", "", 1, -1, 0))
            Label_00A8:
                num3 = 7
                Dim str As String = Strings.Mid(str3, &H10, (Strings.Len(str3) - 15))
            Label_00BD:
                num3 = 8
                str3 = Strings.Left(str3, 15)
            Label_00C9:
                num3 = 9
                Dim num As Integer = 1
            Label_00CF:
                num3 = 10
                Dim str2 As String = ""
            Label_00D9:
                num3 = 11
                Dim str4 As String = ""
            Label_00E4:
                num3 = 12
                Dim num6 As Integer = Strings.Len(str3)
                Dim num2 As Integer = 1
                goto Label_0150
            Label_00F5:
                num3 = 13
                num = (num + 4)
            Label_00FD:
                num3 = 14
                If (num <= 15) Then
                    goto Label_010F
                End If
            Label_0106:
                num3 = 15
                num = (num - 15)
            Label_010F:
                num3 = &H10
                str4 = Strings.Mid(str3, num, 1)
            Label_011D:
                num3 = &H11
                If Information.IsNumeric(str4) Then
                    goto Label_0156
                End If
            Label_012C:
                num3 = &H13
                str2 = (str2 & StringType.FromInteger((Strings.Asc(str4) - &H41)))
            Label_0146:
                num3 = 20
                num2 += 1
            Label_0150:
                If (num2 <= num6) Then
                    goto Label_00F5
                End If
            Label_0156:
                num3 = &H15
                Me.Response.Write("ANL5.0.NET-2005.04.31<br>")
            Label_016A:
                num3 = &H16
                Me.Response.Write(String.Concat(New String() { "Licensed to : ", Me.appsettings.license, " (", str2, ") ", str }))
            Label_01BC:
                num3 = &H17
                Me.Response.Write("")
            Label_01D0:
                num3 = &H18
                Me.Response.End
                goto Label_02AB
            Label_01E4:
                num4 = 0
                Select Case (num4 + 1)
                    Case 0
                        goto Label_0000
                    Case 1
                        goto Label_0010
                    Case 2
                        goto Label_0020
                    Case 3
                        goto Label_0039
                    Case 4
                        goto Label_0051
                    Case 5
                        goto Label_007A
                    Case 6
                        goto Label_0082
                    Case 7
                        goto Label_00A8
                    Case 8
                        goto Label_00BD
                    Case 9
                        goto Label_00C9
                    Case 10
                        goto Label_00CF
                    Case 11
                        goto Label_00D9
                    Case 12
                        goto Label_00E4
                    Case 13
                        goto Label_00F5
                    Case 14
                        goto Label_00FD
                    Case 15
                        goto Label_0106
                    Case &H10
                        goto Label_010F
                    Case &H11
                        goto Label_011D
                    Case &H12
                        goto Label_012A
                    Case &H13
                        goto Label_012C
                    Case 20
                        goto Label_0146
                    Case &H15
                        goto Label_0156
                    Case &H16
                        goto Label_016A
                    Case &H17
                        goto Label_01BC
                    Case &H18
                        goto Label_01D0
                    Case &H19, &H1A
                        goto Label_02AB
                End Select
            Catch obj1 As Object When (?)
                Dim exception1 As Exception = DirectCast(obj1, Exception)
                ProjectData.SetProjectError(exception1)
                exception = exception1
                If (num4 = 0) Then
                    num4 = num3
                    Select Case num5
                        Case 1
                            goto Label_01E4
                    End Select
                    Throw
                End If
            End Try
            Throw exception
        Label_02AB:
            If (num4 <> 0) Then
                ProjectData.ClearProjectError
            End If
        End Sub
Event Clipboard