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. Another GoTo Hell

Another GoTo Hell

Scheduled Pinned Locked Moved The Weird and The Wonderful
securityhelpannouncementcareer
6 Posts 5 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

    This really takes the biscuit, just wrong on so many levels...

    Private Function utilCheckSecurity(recSet As DAO.Recordset, userSet As DAO.Recordset, fileNo As String) As Integer

    On Error GoTo errorCUS
    
    If fileNo = "3" Then GoTo utilCSUpdate  ' no secclass on table
    
    If IsNull(recSet!\[SecurityClass\]) Then GoTo utilCSUpdate
    
    If Len(recSet!\[SecurityClass\]) = 0 Then GoTo utilCSUpdate
    
    If recSet!\[SecurityClass\] Like userSet!\[updateclass\] Then GoTo utilCSUpdate
    
    If recSet!\[SecurityClass\] Like userSet!\[readclass\] Then GoTo UtilCSRead
    
    utilCheckSecurity = 0  ' We fail
    Exit Function
    

    UtilCSRead:

    utilCheckSecurity = 1    ' Can only read the record
    Exit Function
    

    utilCSUpdate:
    utilCheckSecurity = 2 ' Can update the record
    Exit Function

    errorCUS:
    If Err = 3265 Then Resume utilCSUpdate ' no security field
    message "Error " & Format(Err, "######") & " " & Error, "UtilCheckSecurity"
    Exit Function
    End Function

    N S A 3 Replies Last reply
    0
    • R Rob Grainger

      This really takes the biscuit, just wrong on so many levels...

      Private Function utilCheckSecurity(recSet As DAO.Recordset, userSet As DAO.Recordset, fileNo As String) As Integer

      On Error GoTo errorCUS
      
      If fileNo = "3" Then GoTo utilCSUpdate  ' no secclass on table
      
      If IsNull(recSet!\[SecurityClass\]) Then GoTo utilCSUpdate
      
      If Len(recSet!\[SecurityClass\]) = 0 Then GoTo utilCSUpdate
      
      If recSet!\[SecurityClass\] Like userSet!\[updateclass\] Then GoTo utilCSUpdate
      
      If recSet!\[SecurityClass\] Like userSet!\[readclass\] Then GoTo UtilCSRead
      
      utilCheckSecurity = 0  ' We fail
      Exit Function
      

      UtilCSRead:

      utilCheckSecurity = 1    ' Can only read the record
      Exit Function
      

      utilCSUpdate:
      utilCheckSecurity = 2 ' Can update the record
      Exit Function

      errorCUS:
      If Err = 3265 Then Resume utilCSUpdate ' no security field
      message "Error " & Format(Err, "######") & " " & Error, "UtilCheckSecurity"
      Exit Function
      End Function

      N Offline
      N Offline
      Nagy Vilmos
      wrote on last edited by
      #2

      It's VB6, so it's bound to stink. But that is a real piece of spaghetti goto numpty code. I hope it was 'a co-worker' and not you who produced it. ;)


      Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

      R 1 Reply Last reply
      0
      • N Nagy Vilmos

        It's VB6, so it's bound to stink. But that is a real piece of spaghetti goto numpty code. I hope it was 'a co-worker' and not you who produced it. ;)


        Panic, Chaos, Destruction. My work here is done. Drink. Get drunk. Fall over - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre I cannot live by bread alone. Bacon and ketchup are needed as well. - Trollslayer Have a bit more patience with newbies. Of course some of them act dumb - they're often *students*, for heaven's sake - Terry Pratchett

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

        Not really a co-worker, he'd left by the time I joined the company - its actually VBA, but you're on the right lines. I wonder when Microsoft will get round to beefing up VBA in Office app's to a parity with .NET, if ever. The same dev was fond of bad names too. So a function called "CheckXXX" may actually end up updating XXX. Consequently, I have to actually look at every damn function to see what its really doing by studying the code. I'm working on a bit no-ones touched for years but a bug has surfaced - its probably got lots there, but nobody wants to touch the code on a "if its not broke don't fix it", but we get miscelleaneous data errors which lead me to suspect it is broke. I'm strongly considering moving on. To me, even use of VB doesn't excuse that sort of coding. That was considered bad when "Goto considered harmful" was written, and I was 1 year old then!!! When you can fit so many no-no's into such a short function, imagine what its like when you hit one of his 1000-liners. My head hurts.

        1 Reply Last reply
        0
        • R Rob Grainger

          This really takes the biscuit, just wrong on so many levels...

          Private Function utilCheckSecurity(recSet As DAO.Recordset, userSet As DAO.Recordset, fileNo As String) As Integer

          On Error GoTo errorCUS
          
          If fileNo = "3" Then GoTo utilCSUpdate  ' no secclass on table
          
          If IsNull(recSet!\[SecurityClass\]) Then GoTo utilCSUpdate
          
          If Len(recSet!\[SecurityClass\]) = 0 Then GoTo utilCSUpdate
          
          If recSet!\[SecurityClass\] Like userSet!\[updateclass\] Then GoTo utilCSUpdate
          
          If recSet!\[SecurityClass\] Like userSet!\[readclass\] Then GoTo UtilCSRead
          
          utilCheckSecurity = 0  ' We fail
          Exit Function
          

          UtilCSRead:

          utilCheckSecurity = 1    ' Can only read the record
          Exit Function
          

          utilCSUpdate:
          utilCheckSecurity = 2 ' Can update the record
          Exit Function

          errorCUS:
          If Err = 3265 Then Resume utilCSUpdate ' no security field
          message "Error " & Format(Err, "######") & " " & Error, "UtilCheckSecurity"
          Exit Function
          End Function

          S Offline
          S Offline
          StM0n
          wrote on last edited by
          #4

          ' We fail

          Oh yeah... they certainly did...

          (yes|no|maybe)*

          S 1 Reply Last reply
          0
          • R Rob Grainger

            This really takes the biscuit, just wrong on so many levels...

            Private Function utilCheckSecurity(recSet As DAO.Recordset, userSet As DAO.Recordset, fileNo As String) As Integer

            On Error GoTo errorCUS
            
            If fileNo = "3" Then GoTo utilCSUpdate  ' no secclass on table
            
            If IsNull(recSet!\[SecurityClass\]) Then GoTo utilCSUpdate
            
            If Len(recSet!\[SecurityClass\]) = 0 Then GoTo utilCSUpdate
            
            If recSet!\[SecurityClass\] Like userSet!\[updateclass\] Then GoTo utilCSUpdate
            
            If recSet!\[SecurityClass\] Like userSet!\[readclass\] Then GoTo UtilCSRead
            
            utilCheckSecurity = 0  ' We fail
            Exit Function
            

            UtilCSRead:

            utilCheckSecurity = 1    ' Can only read the record
            Exit Function
            

            utilCSUpdate:
            utilCheckSecurity = 2 ' Can update the record
            Exit Function

            errorCUS:
            If Err = 3265 Then Resume utilCSUpdate ' no security field
            message "Error " & Format(Err, "######") & " " & Error, "UtilCheckSecurity"
            Exit Function
            End Function

            A Offline
            A Offline
            Allan Thomas
            wrote on last edited by
            #5

            Pfft. That's nothing I'm currently 'fixing' an email service in c# that was somewhat similar except the person who coded it was doing logical checks before data checks. They were checking a from address (in a nice if tree) to determine how it fit into the system and then checking the content of the email (the same code used multiple times). Then to top that off there were goto statements so after certain sections of testing was completed then move on to the next 'step'. This also has no comments, documentation, etc so I'm having a fun time refactoring it.

            1 Reply Last reply
            0
            • S StM0n

              ' We fail

              Oh yeah... they certainly did...

              (yes|no|maybe)*

              S Offline
              S Offline
              Stefan_Lang
              wrote on last edited by
              #6

              At least that comment was making sense :laugh:

              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