Link to home
Start Free TrialLog in
Avatar of Milewskp
MilewskpFlag for Canada

asked on

On Error statement syntax

This VBA statement:
  On Error gcfHandleErrors Then GoTo PROC_ERR

occurs in the EE question:
https://www.experts-exchange.com/questions/22129974/How-to-find-the-name-of-the-calling-routine.html.

But I couldn't get it to work. Does VBA actually allow this syntax? If so, how do you get it to work?
Avatar of jefftwilley
jefftwilley
Flag of United States of America image

this appears to be

2. The global variable gcfHandleErrors is set to FALSE during development so crashes stop at the offending line rather than it going into the global error handler.

Do you have a global boolean variable called gcfHandleErrors?
SOLUTION
Avatar of sirbounty
sirbounty
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Milewskp

ASKER

Hi Jeff,
Yes, I have set up a global boolean constant called gcfHandleErrors. Here is my code:

Public Const gcfHandleErrors As Boolean = False
Function test()
    Dim a As Integer
   
    On Error gcfHandleErrors Then GoTo PROC_ERR
    a = 1 / 0
    Exit Function
   
PROC_ERR:
   
End Function

But the statement won't even compile. Does it compile on your PC?
No, When I paste that into a module it immediately changes the On Error statement to red
this seems to get it past the edit error but is it the same? Not Sure

    If gcfHandleErrors Then GoTo PROC_ERR
Seems redundant. It's like a global "stop in your tracks" thing I think that Luke came up with to build his array for error debugging. I believe, and don't quote me, that this is a part of some application that he sells...but I can't be sure. Are you trying to implement a larger error handling solution than a hardcoded Module/function name error description solution?
J
Hi Jeff,
I've very seen this syntax before, and was just wondering if it is valid.
I'm trying it, like you are, in VBA. Perhaps it's meant for a VB app...but I can't tell you if there's a difference. What I know is the on error statement doesn't execute on any condition other than if there IS an error. So the method seems wrong to me. And if it's testing for the boolean value, then what's it supposed to do if the boolean is false?

I would suggest e-mailing Luke...and have him tell you the ins and outs...and whether it's something specific to his pre-rolled app, or if it can or will work with any old Database.

My testing of it.....Failed.

J
I've asked other experts to have a look as well.
Luke states:

<quote>
.. It basically works like this:

Sub MyName()
  PushStack "MyName"
  On Error gcfHandleErrors Then GoTo PROC_ERR

  < procedure code goes here >

PROC_EXIT:
  PopStack
  Exit Sub

PROC_ERR:
  GlobalErrorHandler
  Resume PROC_EXIT
End Sub  
</quote>

As is, it doesn't work. So either Luke wrote it as a kind of skeleton or he is wrong; even experts may make errors from time to time ...

/gustav
Does anyone have Luke's email?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Jeff, I'll try that.
Did you find a solution?

/gustav
No, I never got a response from Luke.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The consensus is that VBA doesn't allow this syntax. I will split points equally between all participants. Thanks everyone from your input!