Home All Groups Group Topic Archive Search About

error making function call with multiple parameters to dll

Author
21 Mar 2006 5:11 PM
Sue
Hi, I am trying to make a function call with multiple parameters to a
dll, but I always get a type mismatch error. Strangely the error does
not happen if I pass a single parameter:


The two functions in my dll are:
Public Function testF(ByVal st As String) As Integer
MsgBox st
testF = 5
End Function

Public Function testF2(ByVal st1 As String, ByVal st2 As String) As
Integer
MsgBox st1, st2
testF2 = 100
End Function

The function calls I make are:

1. --no error----
Dim x, y As Integer
x = t.testF("testing")
MsgBox "x = " +  x

2. --- type mismatch error---
y = t.testF2("one", "two")
MsgBox "y= " + y

I tried calling the function different ways still I get the error
3. ---type mismatch error-----
y = t.testF2(st1:="one ", st2:="two")
MsgBox "y= " + y


So what am I doing wrong? Should I declare or call the function a
different way? Or is it possible that I can only pass one parameter to
a dll function?

Help please! I wasted days on this already....
Thank you very much.

Author
21 Mar 2006 5:22 PM
Ken Halter
Show quote Hide quote
"Sue" <sea_***@hotmail.com> wrote in message
news:1142961084.801406.260040@g10g2000cwb.googlegroups.com...
> Hi, I am trying to make a function call with multiple parameters to a
> dll, but I always get a type mismatch error. Strangely the error does
> not happen if I pass a single parameter:
>
>

> Public Function testF2(ByVal st1 As String, ByVal st2 As String) As
> Integer
> MsgBox st1, st2
> testF2 = 100
> End Function
>
> 2. --- type mismatch error---
> y = t.testF2("one", "two")
> MsgBox "y= " + y
>
> Help please! I wasted days on this already....

Then... you'll hate yourself when you find out where the error is coming
from <g>

You're passing 2 strings to the MsgBox function. It expects one string. The
second param for the MsgBox method tells it which buttons/icons to show.
'====
Private Sub Command1_Click()
   Call MsgBox("one", "two") 'Same error as you get
End Sub
'====

To show both params in one box, use:

MsgBox String1 & vbCrLf & String2

--
Ken Halter - MS-MVP-VB - Please keep all discussions in the groups..
DLL Hell problems? Try ComGuard - http://www.vbsight.com/ComGuard.htm
Are all your drivers up to date? click for free checkup

Author
21 Mar 2006 5:54 PM
Sue
Thank you SO much -- this REALLY saved me - I was beginning to wonder
if I should think of alteranate ways, like concatenating all parameters
after converting all to the same type, and then splitting them inside
the function to extract the separate ones. Thank you again!!!
Author
21 Mar 2006 5:44 PM
Bob Butler
"Sue" <sea_***@hotmail.com> wrote in message
news:1142961084.801406.260040@g10g2000cwb.googlegroups.com
> 1. --no error----
> Dim x, y As Integer

Ken pointed out the reason for the error but you should be aware that x is
being declared as a Variant in the above statement.  You need to specify the
type on all variables as in:
Dim x As Integer, y As Integer


--
Reply to the group so all can participate
VB.Net: "Fool me once..."
Author
21 Mar 2006 5:55 PM
Sue
Thanks for this tip also!!
Author
21 Mar 2006 7:21 PM
Sue
Thanks for this tip also!!

Bookmark and Share