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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Objects to Class Functions (Methods)

Status
Not open for further replies.

gavjb

Technical User
Jul 5, 2005
67
GB
Hi,

I have just finished writing my ErrorLogger Class, the Main Method in the Function takes 3 Parameters, but when I try to call this from a function, I getan Type Mismatch Error.

the Declaration of the Method in the Class is as follows

Code:
Public Function LogError(ByVal objError As Error, ByVal strProcName As String, ByVal strUserInput As String)
' Summary  : function that logs error to table or file
' History  : [Gavin Blackford] 22/03/2006     Created
'------------------------------------------------------------------------
    
    Select Case OutputType
    
        Case 1 ' Error table
            Call LogTable(objError, strProcName, Nz(strUserInput, ""))
    
        Case 2 ' Error File
            Call LogFile(objError, strProcName, Nz(strUserInput, ""))
    
        Case 3 ' Both
            Call LogTable(objError, strProcName, Nz(strUserInput, ""))
            Call LogFile(objError, strProcName, Nz(strUserInput, ""))
            
    End Select

End Function

and in the function I have the following code to call this Class Method

Code:
    Set objErrors = New clsERRErrors
    objErrors.OutputType = ErrorLogTable
    Call objErrors.LogError(objError, strProcName, varParams(4))

After taking out each parameter the problem stops as soon as I remove objError, does anyone know anyway I can get this to work without having to pass every value from the Error object as individual variables

Thanks,


Gavin,
 
I think the mismatch is because you try to pass (or have the method try to enforce passing) the object by value. Try changing to by reference.

What is this "Error" object? Someting you've created? Be aware that if you reference either DAO or ADO, both of these has an Error object, and you might be getting one of those objects ... perhaps be explicit, if it's another kind of error object?

[tt]Public Function LogError(ByVal objError As mylib.Error, ...[/tt]

Roy-Vidar
 
Hi,

What I am trying to do is pass the Err Object to my ErrorClass so It can log the err number & description to a log file/table.

I tired setting the objError to ByRef, but it made no diffrence.
 
Is this Err Object something you have created yourself? If so, you need to prefix it with the classname in the method header, else you will continue to have type mismatches because when you use the unqualified "as error" in the method declaration, you will get whatever error object is "highest" in the reference list. My guess - either ADO, DAO or perhaps Excel ...

If this is the Err object giving err.description, err.number ... I don't think, you can pass it. Pass the relevant properties of it in stead.

Roy-Vidar
 
Thanks, I had forgotten you cant pass the Error Object to classes etc..

Anyway all working now
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top