Another GoTo Hell
-
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 FunctionerrorCUS:
If Err = 3265 Then Resume utilCSUpdate ' no security field
message "Error " & Format(Err, "######") & " " & Error, "UtilCheckSecurity"
Exit Function
End Function -
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 FunctionerrorCUS:
If Err = 3265 Then Resume utilCSUpdate ' no security field
message "Error " & Format(Err, "######") & " " & Error, "UtilCheckSecurity"
Exit Function
End FunctionIt'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
-
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
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.
-
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 FunctionerrorCUS:
If Err = 3265 Then Resume utilCSUpdate ' no security field
message "Error " & Format(Err, "######") & " " & Error, "UtilCheckSecurity"
Exit Function
End Function -
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 FunctionerrorCUS:
If Err = 3265 Then Resume utilCSUpdate ' no security field
message "Error " & Format(Err, "######") & " " & Error, "UtilCheckSecurity"
Exit Function
End FunctionPfft. 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.
-
At least that comment was making sense :laugh: