Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

byref argument type mismatch

Status
Not open for further replies.

striker73

MIS
Jun 7, 2001
376
US
I am getting a ByRef argument type mismatch error in my code. My function takes in an integer...

'##### Function #####
Public MyFunction (abc as integer)
'----insert code here ----
End Function


On my form, I have the code:
Call MyFunction(typeidentifier)


It is at this point that I get the strange error. Any idea?
 
The error indicates that typeidentifier is not defined as Integer.

Unrelated to the error, a function returns a value and the abscence of an As clause after the closing paren defaults the return to a Variant type. This may not be what you want but it isn';t the error since you use Call to invoke the function. Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Your declaration should be Public FUNCTION MyFunction(abc As Integer) As Integer

(but I suspect that you have mistyped your post since leaving out the Function keyword will give a compile error).

If you don't want it to return a value, it should be Public SUB MyFunction ...

Are you using Option Explicit? If not, I strongly recommend that you do and explicitly declare everything using a naming convention ( eg all integers start i, longs start l, booleans b, etc). It's also worth using another prefix to indicate the scope (local / module / global).

For a small amount of extra effort, you get a clearer, more maintainable design and avoid a lot of irritating bugs (like this one!) during development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top