Solved

Passing an array to a VB dll from a VB app

Posted on 2003-10-22
6
181 Views
Last Modified: 2010-05-03
Hello,
I have the following error with the code below.
Run-time error 13
Type Mismatch

'this code lies within a form on a vb appliation it calls a dll that was also created by vb
Private Sub vbAppSub()
 Dim array(1 to 5) as String  'note: if I change this line to variant I get rt error 381 Subscript out of range
 array(1) = "a"
 array(2) = "b"
 array(3) = "c"
 array(4) = "d"
 array(5) = "e"

 Dim objdll as object
 Set objdll = CreateObject("mydll.class")
 objdll.sendArray( array )                               'error is here
 set objdll = nothing

End Sub

///////////

'this code lies within a class module within a vb activeX dll
Public Function sendArray( passedArray() As Variant) As Boolean
 'code here in never executed
End Function


My question is how can I send arrays to dll's? what kinds of arrays can I send? what kinds of arrays can I not send?
Thanks
ff
0
Comment
Question by:funkyfinger
  • 4
6 Comments
 
LVL 2

Author Comment

by:funkyfinger
ID: 9603071
Substituting the following code in for the activeX dll has the same effect

Public Function sendArray(ParamArray passedArray()) As Boolean
 'code here never gets executed
End Sub
0
 
LVL 2

Author Comment

by:funkyfinger
ID: 9603090

I should say that substituting the following code has the same effect unless you change line 2 to
Dim array(1 to 5) as Variant
Then I no longer get the run time error 381 just the orgional error 13
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 9603415
What about:

Public Function sendArray(passedArray) As Boolean
'code
End Function
0
 
LVL 2

Author Comment

by:funkyfinger
ID: 9603608
I tried your code passing both a array of string and variant both resulted in

run-time error 381
subscript out of range

thks
ff
0
 
LVL 2

Accepted Solution

by:
funkyfinger earned 0 total points
ID: 9603776
I found the solution......
The two varibles here were the type of array I was sending and the parameters the function from the dll was expecting

this (from line 2) will work with the following code in the dll
2:
   Dim array(1 to 5) as Variant

dll:
Public Function sendArray(passedArray As Variant) As Boolean
 'code
End Function

 -- OR --

this (from line 2) will work with the following code in the dll
2:
   Dim array(1 to 5) as String

dll:
Public Function sendArray(passedArray() As String) As Boolean
 'code
End Function


Hope that this may help someone with a similar problem in the future.
ff
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question