Passing user data type to function causes type mismatch error 
Author Message
 Passing user data type to function causes type mismatch error

I have a module that has a public data type declared as follows;

+++++++++++++++++++++
Public Type MailMSG
        displayname as string
        txt as string
        subj as string
        confirm as boolean
        sender as string
End Type

My function starts as follows

Public Function QuickSend(sMSG as MailMSG)
        Stuff in the function
End Function
+++++++++++++++++++++++++

Now I pass the the type as an argument to the function as follows;

+++++++++++++
Sub Send_Click()
Dim mymessage as MailMSG

mymessage.displayname = "Lemon, Philip"
mymessage.txt = "Yadda, Yadda, Yadda"
mymessage.subj = "Test Subject"
mymessage.confirm = True

QuickSend(mymessage)
+++++++++++++
When I call the function using the last line I get a Type Mismatch
error.  Why?

Phil Lemon



Tue, 04 Dec 2001 03:00:00 GMT  
 Passing user data type to function causes type mismatch error

Phil,

You need to either use the syntax:

    Dim V as Variant

    V = QuickSend(mymessage)

or (if you don't care about the return value):

    QuickSend mymessage

no parenthesis around the argument in the second case.  IIRC
"QuickSend(mymessage)" as your tried tells VB to pass the arguments by
value - which of course conflicts with the implicit By Reference in your
function declaration.

HTH

Peter


Quote:
>I have a module that has a public data type declared as follows;

>+++++++++++++++++++++
>Public Type MailMSG
> displayname as string
> txt as string
> subj as string
> confirm as boolean
> sender as string
>End Type

>My function starts as follows

>Public Function QuickSend(sMSG as MailMSG)
> Stuff in the function
>End Function
>+++++++++++++++++++++++++

>Now I pass the the type as an argument to the function as follows;

>+++++++++++++
>Sub Send_Click()
>Dim mymessage as MailMSG

>mymessage.displayname = "Lemon, Philip"
>mymessage.txt = "Yadda, Yadda, Yadda"
>mymessage.subj = "Test Subject"
>mymessage.confirm = True

>QuickSend(mymessage)
>+++++++++++++
>When I call the function using the last line I get a Type Mismatch
>error.  Why?

>Phil Lemon



Tue, 04 Dec 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Type mismatch on user defined data type

2. Prob. w\ TYPE data type: err:Type Mismatch

3. error: type mismatch - when passed prameters into function in asp page

4. Passing a Recordset to function gives Type mismatch (error 13)

5. Mdac2.6 to Mdac2.7 causes Type Mismatch Runtime Error 13

6. Type Mismatch when passing object to function

7. Q: variant data type with user defined data type

8. type mismatch error when passing object

9. Get error: Disallowed implicit conversion from data type varchar to data type money

10. Data type conversion error when saving numeric data types

11. VBScript with ASP using Len() function gives Type Mismatch error

 

 
Powered by phpBB® Forum Software