compile error on Function? Don't know whats wrong.... 
Author Message
 compile error on Function? Don't know whats wrong....

Please help:
I keep getting an compile error on this function (first line):
(isn't it possible to get two values inside?)

Function call_funct(typ, cell)
    a = get_modules(cell, typ)
End Function

Thanx
Markus Heckmann



Fri, 19 Sep 2003 22:30:54 GMT  
 compile error on Function? Don't know whats wrong....
Markus,

When I copy the copy you wrote and compile, I don't receive an error.
However, there several things about this code which can cause problems and
should be changed.

1)  Functions return values, that is what differentiates them from
SubRoutines.  Because it returns a value, it should say what kind of value
it is returning:

Function call_funct(typ, cell) As Integer       '  or String, or Date, or
something

2)  You should always say what type of variables  you are using.  It is true
that VBA will supply default types but it is good practice to always declare
the type of your variable.  Another good practice is to put "Option
Explicit" at the beginning of each module:

Option Explicit

Function call_func(typ as String, cell as integer) As Integer
        Dim a as integer

        a = get_modules(cell, typ)
End Function

3)  There are certain words which are used in VBA for special purposes.
These are referred to as "Reserved Words".  Some of these can be used as
variables and some can't.  The ones which can be used often cause unexpected
side effects when they are used.  It is best to avoid reserved words.

Function call_MyFunction(ByVal strType as String, ByVal intCell as integer)
As Integer
        Dim a as integer

        a = get_modules(intCell, strType)
End Function

4)  Since functions return values you must tell the function which value is
to be returned.  Do this by assigning the value to the name of the function:

Function call_MyFunction(strType as String, intCell as integer) As Integer
        Dim a as integer

        a = get_modules(intCell, strType)

        call_MyFunction = a
End Function

Following the guidelines for good coding will probably eliminate 80% of
error messages and unexpected side effects.  As I said, your code compiles
on my computer, under Access 2000, with no errors but the way it is written
there will be problems actually trying to use the function.  Try writing
following these guidelines and see if you still get errors.

--
Lee Robinson
Agility, Inc.


Quote:
> Please help:
> I keep getting an compile error on this function (first line):
> (isn't it possible to get two values inside?)

> Function call_funct(typ, cell)
>     a = get_modules(cell, typ)
> End Function

> Thanx
> Markus Heckmann



Sat, 20 Sep 2003 00:06:29 GMT  
 compile error on Function? Don't know whats wrong....
Is the variable "a" declared somewhere?  If not, do you have Option Explicit
set?  What compile-error message do you get?

--

Dirk Goldgar
(remove NOSPAM from reply address)


Quote:
> Please help:
> I keep getting an compile error on this function (first line):
> (isn't it possible to get two values inside?)

> Function call_funct(typ, cell)
>     a = get_modules(cell, typ)
> End Function

> Thanx
> Markus Heckmann



Sat, 20 Sep 2003 00:04:54 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. syntax error but don't know where

2. don't know how to handle error

3. ADO Error! Don't know why

4. scriptcontrol error messages don't say what function they are in

5. Whats wrong with this... (dealing with ini functions)

6. Help-don't know what i'm missing

7. Don't know if i'm in the right newsgroup

8. NEWBIE : Getting Error Object required Can anyone point out whats wrong

9. Runtime Error 429 - Whats Wrong?

10. Runtime Error 429 - Whats Wrong?

11. Runtime Error 429 - Whats Wrong?

12. Microsoft doesn't know whats happening??

 

 
Powered by phpBB® Forum Software