Solved

Passing an array to a VB dll from a VB app

Posted on 2003-10-22
6
183 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

696 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