Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. YAVBH

YAVBH

Scheduled Pinned Locked Moved The Weird and The Wonderful
oraclehelpcareer
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rob Grainger
    wrote on last edited by
    #1

    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 tryAgain

        ElseIf 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...

    P J 2 Replies Last reply
    0
    • R Rob Grainger

      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 tryAgain

          ElseIf 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...

      P Offline
      P Offline
      Peter_in_2780
      wrote on last edited by
      #2

      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.

      R 1 Reply Last reply
      0
      • P Peter_in_2780

        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.

        R Offline
        R Offline
        Rob Grainger
        wrote on last edited by
        #3

        Yes, like the unique constraint in there, I feel "violated"

        1 Reply Last reply
        0
        • R Rob Grainger

          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 tryAgain

              ElseIf 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...

          J Offline
          J Offline
          Julien Villers
          wrote on last edited by
          #4

          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

          R 1 Reply Last reply
          0
          • J Julien Villers

            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

            R Offline
            R Offline
            Rob Grainger
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups