functions calling other functions 
Author Message
 functions calling other functions

I have a form in which I want private sub procedures to call a public function in
a public module which in turn refers (calls?) another function in the same public
module. Both functions return 0 if there were no errors and various integers if
there was an error (each type of error will return a different integer). I'm doing
this to avoid duplicating code. Is there any downside to this scenario and to
having one function feed into another, especially in terms of error handling?
Thanks in advance.

Maureen



Sat, 25 Oct 2003 08:15:53 GMT  
 functions calling other functions
It's normal for one function to call another. You can do that as
safely and efficiently as using the built-in functions like Int().

The simplest way to handle errors is with error handling in *each*
procedure. Otherwise tracking down where the error occurred can be
awkward. Example:
- Procedure A calls function B.
- A has error handling; B does not.
- An error occurs in B.
- Because B was called from A and error handling is running there,
  B returns an error for A to handle.
Now you're told that A is handling an error, but there's nothing
wrong with A, and you don't know where the error occurred. There
are cases where this is useful, but in general it's easier to debug
your application if each procedure has its own error handling.

One of the best side-effects of the approach you suggest is ease of
debugging and maintenance. If the code needs modifying, it's much
easier and safer if you know there's only one place to change than
if you must find and fix multiple ocurrances that could be anywhere.

You'll often need to pass references into the generic procedure.
For example, you can pass a ref to the current form:
    Function CheckThis(frm As Form)
    End Function
call it like this:
    Call CheckThis(Me)
and then use "frm" to refer to any controls/properties of the form.

Quote:

> I have a form in which I want private sub procedures to call a public function in
> a public module which in turn refers (calls?) another function in the same public
> module. Both functions return 0 if there were no errors and various integers if
> there was an error (each type of error will return a different integer). I'm doing
> this to avoid duplicating code. Is there any downside to this scenario and to
> having one function feed into another, especially in terms of error handling?
> Thanks in advance.

> Maureen

--
Perth, Western Australia
Tips for MS Access users at:
        http://odyssey.apana.org.au/~abrowne


Sat, 25 Oct 2003 10:37:53 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Calling Function in CBF from Toolbar via a Public Function

2. eval function? how to call dynamic function name

3. Calling a sub or function using a variable through another sub or function

4. Function call via string parameter in other function ?

5. multiple functions calling a common DAO function

6. Get the name of a function that calls another function

7. Setting a call back function to a function inside a control

8. DBGrid Delete Key function not working on some DBGrids while it works on others

9. Helping others convert Functions to APIs, e.g..

10. Helping others convert Functions to APIs, e.g..

11. calling access querydef that calls a user defined access function

12. Can an ActiveX DLL function call a function in the calling (controlling) module?

 

 
Powered by phpBB® Forum Software