Click here to Skip to main content
15,895,283 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.

 
GeneralAre you sure that it's not null? PinPopular
JeremyBob22-Jul-10 21:39
JeremyBob22-Jul-10 21:39 
GeneralRe: Are you sure that it's not null? Pin
Yusuf23-Jul-10 13:37
Yusuf23-Jul-10 13:37 
GeneralRe: Are you sure that it's not null? Pin
ThatsAlok25-Jul-10 20:42
ThatsAlok25-Jul-10 20:42 
GeneralRe: Are you sure that it's not null? Pin
J4amieC26-Jul-10 6:09
J4amieC26-Jul-10 6:09 
GeneralRe: Are you sure that it's not null? Pin
JeremyBob25-Jul-10 22:38
JeremyBob25-Jul-10 22:38 
GeneralRe: Are you sure that it's not null? Pin
Single Step Debugger27-Jul-10 5:58
Single Step Debugger27-Jul-10 5:58 
GeneralRe: Are you sure that it's not null? Pin
Lutosław30-Jul-10 2:20
Lutosław30-Jul-10 2:20 
GeneralYAVH - Yet another VBA horror Pin
Rob Grainger22-Jul-10 1:13
Rob Grainger22-Jul-10 1:13 
Well another from the goldmine of coding horrors that is VBA...

Here, two tables have similar structures, and need to be processed similarly (don't ask)...
Naturally, I paraphrase to protect the innocent.

Sub SomeSub()
    Dim rs As Recordset
    Dim tblname As String
    Dim i As Integer

    On Error GoTo Err_Handler

    tblname = "Table1"

    For i = 0 To 1
        Set rs = db.OpenRecordset("SELECT * FROM " & tblname & " WHERE ... ")
    
        ' Code to process records here
        ' Including...

NextTable:

        tblname = "Table2"
    Next i

    ' Remainder of code

    Exit Sub

Err_Handler:

    ' Code to log error
    Resume NextTable   ' Note that there's no real error-checking, just logging.
End Sub


(I should mention that code to process records here expands to a couple of hundred lines)

Why, oh why, not define another procedure and call it...
Sub SomeSub()
    ' Replacement for above
    ProcessRecords "Table1"
    ProcessRecords "Table2"
End Sub

Sub ProcessRecords(tableName AS String)
    ' Code to process records here
    ' When errors occur, can simply return (ideally after some real error-checking)
End Sub


Makes you want to hurl.
GeneralRe: YAVH - Yet another VBA horror Pin
Oakman22-Jul-10 3:09
Oakman22-Jul-10 3:09 
GeneralRe: YAVH - Yet another VBA horror Pin
Dan Pratt22-Jul-10 3:25
Dan Pratt22-Jul-10 3:25 
GeneralRe: YAVH - Yet another VBA horror Pin
Jeremy Hutchinson22-Jul-10 3:36
professionalJeremy Hutchinson22-Jul-10 3:36 
GeneralRe: YAVH - Yet another VBA horror Pin
supercat922-Jul-10 4:55
supercat922-Jul-10 4:55 
GeneralRe: YAVH - Yet another VBA horror Pin
Rob Grainger26-Jul-10 5:59
Rob Grainger26-Jul-10 5:59 
GeneralRe: YAVH - Yet another VBA horror Pin
Hired Mind22-Jul-10 7:12
Hired Mind22-Jul-10 7:12 
GeneralRe: YAVH - Yet another VBA horror Pin
oggenok6423-Jul-10 8:54
oggenok6423-Jul-10 8:54 
GeneralHow to Use Member Variables Pin
Nagy Vilmos19-Jul-10 10:29
professionalNagy Vilmos19-Jul-10 10:29 
GeneralRe: How to Use Member Variables PinPopular
Luc Pattyn19-Jul-10 11:02
sitebuilderLuc Pattyn19-Jul-10 11:02 
GeneralRe: How to Use Member Variables Pin
Nagy Vilmos19-Jul-10 21:36
professionalNagy Vilmos19-Jul-10 21:36 
GeneralRe: How to Use Member Variables Pin
Luc Pattyn19-Jul-10 23:20
sitebuilderLuc Pattyn19-Jul-10 23:20 
GeneralRe: How to Use Member Variables Pin
Robert Rohde20-Jul-10 2:05
Robert Rohde20-Jul-10 2:05 
GeneralRe: How to Use Member Variables Pin
Eddy Vluggen20-Jul-10 2:24
professionalEddy Vluggen20-Jul-10 2:24 
AnswerRe: How to Use Member Variables Pin
Luc Pattyn20-Jul-10 2:58
sitebuilderLuc Pattyn20-Jul-10 2:58 
GeneralRe: How to Use Member Variables Pin
ely_bob22-Jul-10 3:41
professionalely_bob22-Jul-10 3:41 
GeneralRe: How to Use Member Variables Pin
Robert Rohde20-Jul-10 5:35
Robert Rohde20-Jul-10 5:35 
GeneralRe: How to Use Member Variables Pin
Rob Grainger21-Jul-10 23:42
Rob Grainger21-Jul-10 23:42 

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.