Click here to Skip to main content
15,886,788 members

The Weird and The Wonderful

   

The Weird and The Wonderful forum is a place to post Coding Horrors, Worst Practices, and the occasional flash of brilliance.

We all come across code that simply boggles the mind. Lazy kludges, embarrassing mistakes, horrid workarounds and developers just not quite getting it. And then somedays we come across - or write - the truly sublime.

Post your Best, your worst, and your most interesting. But please - no programming questions . This forum is purely for amusement and discussions on code snippets. All actual programming questions will be removed.

 
GeneralRe: QA blooper Pin
Sascha Lefèvre28-Mar-16 23:57
professionalSascha Lefèvre28-Mar-16 23:57 
GeneralRe: QA blooper Pin
phil.o28-Mar-16 23:53
professionalphil.o28-Mar-16 23:53 
GeneralRe: QA blooper Pin
Sascha Lefèvre29-Mar-16 0:00
professionalSascha Lefèvre29-Mar-16 0:00 
GeneralRe: QA blooper Pin
F-ES Sitecore29-Mar-16 1:08
professionalF-ES Sitecore29-Mar-16 1:08 
GeneralRe: QA blooper Pin
Sentenryu29-Mar-16 1:12
Sentenryu29-Mar-16 1:12 
GeneralRe: QA blooper Pin
Nathan Minier30-Mar-16 1:43
professionalNathan Minier30-Mar-16 1:43 
GeneralRe: QA blooper Pin
Brisingr Aerowing30-Mar-16 2:53
professionalBrisingr Aerowing30-Mar-16 2:53 
GeneralPracticing the Dark Arts of Invocation Pin
Rob Grainger24-Mar-16 6:22
Rob Grainger24-Mar-16 6:22 
I think this just speaks for itself...

(I apologise in advance for the pain caused)

How many bad practices can y'all spot in this?

VB
        Function InvokeMember(MethodName As String, _
                Optional ByRef P1 As Object = "!%$", Optional ByRef P2 As Object = "!%$", _
                Optional ByRef P3 As Object = "!%$", Optional ByRef P4 As Object = "!%$", _
                Optional ByRef P5 As Object = "!%$", Optional ByRef P6 As Object = "!%$", _
                Optional ByRef P7 As Object = "!%$", Optional ByRef P8 As Object = "!%$", _
                Optional ByRef P9 As Object = "!%$", Optional ByRef P10 As Object = "!%$", _
                Optional ByRef P11 As Object = "!%$") As Object

            Dim Parms(0) As Object

            If P1.GetType Is GetType(String) Then If P1 = "!%$" Then GoTo a150

            Parms(0) = P1

            If P2.GetType Is GetType(String) Then If P2 = "!%$" Then GoTo a100
            ReDim Preserve Parms(UBound(Parms) + 1) : Parms(UBound(Parms)) = P2
            If P3.GetType Is GetType(String) Then If P3 = "!%$" Then GoTo a100
            ReDim Preserve Parms(UBound(Parms) + 1) : Parms(UBound(Parms)) = P3
            If P4.GetType Is GetType(String) Then If P4 = "!%$" Then GoTo a100
            ReDim Preserve Parms(UBound(Parms) + 1) : Parms(UBound(Parms)) = P4
            If P5.GetType Is GetType(String) Then If P5 = "!%$" Then GoTo a100
            ReDim Preserve Parms(UBound(Parms) + 1) : Parms(UBound(Parms)) = P5
            If P6.GetType Is GetType(String) Then If P6 = "!%$" Then GoTo a100
            ReDim Preserve Parms(UBound(Parms) + 1) : Parms(UBound(Parms)) = P6
            If P7.GetType Is GetType(String) Then If P7 = "!%$" Then GoTo a100
            ReDim Preserve Parms(UBound(Parms) + 1) : Parms(UBound(Parms)) = P7
            If P8.GetType Is GetType(String) Then If P8 = "!%$" Then GoTo a100
            ReDim Preserve Parms(UBound(Parms) + 1) : Parms(UBound(Parms)) = P8
            If P9.GetType Is GetType(String) Then If P9 = "!%$" Then GoTo a100
            ReDim Preserve Parms(UBound(Parms) + 1) : Parms(UBound(Parms)) = P9
            If P10.GetType Is GetType(String) Then If P10 = "!%$" Then GoTo a100
            ReDim Preserve Parms(UBound(Parms) + 1) : Parms(UBound(Parms)) = P10
            If P11.GetType Is GetType(String) Then If P11 = "!%$" Then GoTo a100
            ReDim Preserve Parms(UBound(Parms) + 1) : Parms(UBound(Parms)) = P11

a100:
            On Error GoTo a200
            InvokeMember = DLLClass.InvokeMember(MethodName, _
                Reflection.BindingFlags.InvokeMethod, Nothing, DLlInstance, Parms, Nothing)
            Dim x As Integer
            For x = 0 To UBound(Parms)
                If x = 0 Then P1 = Parms(x)
                If x = 1 Then P2 = Parms(x)
                If x = 2 Then P3 = Parms(x)
                If x = 3 Then P4 = Parms(x)
                If x = 4 Then P5 = Parms(x)
                If x = 5 Then P6 = Parms(x)
                If x = 6 Then P7 = Parms(x)
                If x = 7 Then P8 = Parms(x)
                If x = 8 Then P9 = Parms(x)
                If x = 9 Then P10 = Parms(x)
                If x = 10 Then P11 = Parms(x)
            Next
            Exit Function

a150:
            On Error GoTo a200
            InvokeMember = DLLClass.InvokeMember(MethodName, _
                Reflection.BindingFlags.InvokeMethod, Nothing, DLlInstance, Nothing, Nothing)
            Exit Function

a200:
            Dim m As String = ""

            m = m & "Error invoking Method:  " & MethodName & vbCrLf
            m = m & "Either the Method Name is incorrect (Check Case Sensitivity)" & vbCrLf
            m = m & "Or The Parameter sequence does not match the Methods signature"
            InvokeExitSystem(m)

        End Function


(PS - this is actually VB.NET code).
"If you don't fail at least 90 percent of the time, you're not aiming high enough."
Alan Kay.

GeneralRe: Practicing the Dark Arts of Invocation Pin
Simon_Whale24-Mar-16 6:36
Simon_Whale24-Mar-16 6:36 
GeneralRe: Practicing the Dark Arts of Invocation Pin
Rob Grainger24-Mar-16 13:47
Rob Grainger24-Mar-16 13:47 
GeneralRe: Practicing the Dark Arts of Invocation Pin
Sascha Lefèvre24-Mar-16 7:52
professionalSascha Lefèvre24-Mar-16 7:52 
GeneralRe: Practicing the Dark Arts of Invocation Pin
Brisingr Aerowing24-Mar-16 8:37
professionalBrisingr Aerowing24-Mar-16 8:37 
GeneralRe: Practicing the Dark Arts of Invocation Pin
Rob Grainger24-Mar-16 13:43
Rob Grainger24-Mar-16 13:43 
GeneralRe: Practicing the Dark Arts of Invocation Pin
Brisingr Aerowing24-Mar-16 14:58
professionalBrisingr Aerowing24-Mar-16 14:58 
GeneralRe: Practicing the Dark Arts of Invocation Pin
Brisingr Aerowing24-Mar-16 17:04
professionalBrisingr Aerowing24-Mar-16 17:04 
GeneralRe: Practicing the Dark Arts of Invocation Pin
Kyle Moyer24-Mar-16 10:48
Kyle Moyer24-Mar-16 10:48 
GeneralRe: Practicing the Dark Arts of Invocation Pin
Rob Grainger24-Mar-16 13:42
Rob Grainger24-Mar-16 13:42 
GeneralRe: Practicing the Dark Arts of Invocation Pin
Sinisa Hajnal1-Apr-16 2:52
professionalSinisa Hajnal1-Apr-16 2:52 
GeneralRe: Practicing the Dark Arts of Invocation Pin
Jörgen Andersson24-Mar-16 21:27
professionalJörgen Andersson24-Mar-16 21:27 
GeneralRe: Practicing the Dark Arts of Invocation Pin
Sander Rossel25-Mar-16 12:00
professionalSander Rossel25-Mar-16 12:00 
GeneralRe: Practicing the Dark Arts of Invocation Pin
Rob Grainger26-Mar-16 11:56
Rob Grainger26-Mar-16 11:56 
GeneralRe: Practicing the Dark Arts of Invocation Pin
Sander Rossel26-Mar-16 16:02
professionalSander Rossel26-Mar-16 16:02 
GeneralRe: Practicing the Dark Arts of Invocation Pin
Rob Grainger27-Mar-16 6:31
Rob Grainger27-Mar-16 6:31 
GeneralRe: Practicing the Dark Arts of Invocation Pin
Sander Rossel27-Mar-16 11:42
professionalSander Rossel27-Mar-16 11:42 
GeneralRe: Practicing the Dark Arts of Invocation Pin
Jalapeno Bob30-Mar-16 10:46
professionalJalapeno Bob30-Mar-16 10:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.