YAVBH
-
Yet Another VB Horror! The following is an error-handling block from some old code I'm having to maintain (for my sins)..
errorPAT:
If retryCount < 1000 Then
ElseIf Err.Number = errOdbcCallFailed Then
If InStr(odbcErrorMess(Err), "insert duplicate") > 0 Then ' SQLServer
retryCount = retryCount + 1
Resume tryAgainElseIf InStr(odbcErrorMess(Err), "unique constraint") > 0 And InStr(odbcErrorMess(Err), "violated") > 0 Then ' Oracle retryCount = retryCount + 1 Resume tryAgain ElseIf InStr(odbcErrorMess(Err), "Duplicate key value specified") > 0 Then ' AS400 retryCount = retryCount + 1 Resume tryAgain Else message "Error " & Format(Err, "######") & " " & odbcErrorMess(Err), "P\_ArchiveTag" Exit Sub End If ElseIf Err.Number = errDuplicateValues Then ' duplicate key retryCount = retryCount + 1 Resume tryAgain End If message "Error " & Format(Err, "######") & " " & Error, "P\_ArchiveTag"
End Sub
I think there's ample horrors for a short chunk of code...
-
Yet Another VB Horror! The following is an error-handling block from some old code I'm having to maintain (for my sins)..
errorPAT:
If retryCount < 1000 Then
ElseIf Err.Number = errOdbcCallFailed Then
If InStr(odbcErrorMess(Err), "insert duplicate") > 0 Then ' SQLServer
retryCount = retryCount + 1
Resume tryAgainElseIf InStr(odbcErrorMess(Err), "unique constraint") > 0 And InStr(odbcErrorMess(Err), "violated") > 0 Then ' Oracle retryCount = retryCount + 1 Resume tryAgain ElseIf InStr(odbcErrorMess(Err), "Duplicate key value specified") > 0 Then ' AS400 retryCount = retryCount + 1 Resume tryAgain Else message "Error " & Format(Err, "######") & " " & odbcErrorMess(Err), "P\_ArchiveTag" Exit Sub End If ElseIf Err.Number = errDuplicateValues Then ' duplicate key retryCount = retryCount + 1 Resume tryAgain End If message "Error " & Format(Err, "######") & " " & Error, "P\_ArchiveTag"
End Sub
I think there's ample horrors for a short chunk of code...
It's 8am here. Remind me to never again visit this forum before breakfast. I can see this ruining my whole day (and no, I'm not going to sea, but that's another story.) :vomit: Peter
Software rusts. Simon Stephenson, ca 1994.
-
It's 8am here. Remind me to never again visit this forum before breakfast. I can see this ruining my whole day (and no, I'm not going to sea, but that's another story.) :vomit: Peter
Software rusts. Simon Stephenson, ca 1994.
Yes, like the unique constraint in there, I feel
"violated"
-
Yet Another VB Horror! The following is an error-handling block from some old code I'm having to maintain (for my sins)..
errorPAT:
If retryCount < 1000 Then
ElseIf Err.Number = errOdbcCallFailed Then
If InStr(odbcErrorMess(Err), "insert duplicate") > 0 Then ' SQLServer
retryCount = retryCount + 1
Resume tryAgainElseIf InStr(odbcErrorMess(Err), "unique constraint") > 0 And InStr(odbcErrorMess(Err), "violated") > 0 Then ' Oracle retryCount = retryCount + 1 Resume tryAgain ElseIf InStr(odbcErrorMess(Err), "Duplicate key value specified") > 0 Then ' AS400 retryCount = retryCount + 1 Resume tryAgain Else message "Error " & Format(Err, "######") & " " & odbcErrorMess(Err), "P\_ArchiveTag" Exit Sub End If ElseIf Err.Number = errDuplicateValues Then ' duplicate key retryCount = retryCount + 1 Resume tryAgain End If message "Error " & Format(Err, "######") & " " & Error, "P\_ArchiveTag"
End Sub
I think there's ample horrors for a short chunk of code...
There a very aptly named method/function called 'odbcErrorMess', which neatly sums the whole code block you pasted. Take-away: never shorten your method/function names :)
'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood
-
There a very aptly named method/function called 'odbcErrorMess', which neatly sums the whole code block you pasted. Take-away: never shorten your method/function names :)
'As programmers go, I'm fairly social. Which still means I'm a borderline sociopath by normal standards.' Jeff Atwood
Julien Villers wrote:
Take-away: never shorten your method/function names :)
I don't know, in this case I'd say the variable name is spot on ;-). Must be the only example in the code of a well named variable. I have such treasures as Function names: Function H_WriteRecord1() Function H_WriteRecord2() Function H_WriteRecord3() Note - those are the declarations as they appear. No return type given, all state passed in via global or module-level variables, and nothing to indicate what gets written, what the difference between the three variants is. I suspect "that nearly does what I want, I'll copy and paste it". I also like the "batchHeader" boolean that sometimes outputs a header when true, otherwise when false. I still can't work out the logic governing when the two forms are used. I suspect the originator may be a closet worshipper of The FSM[^]. I just wished he hadn't felt the need to spread noodly appendages through the code I'm now tasked with maintaining.