Making array in DLL available in VBA?

  • Thread starter Thread starter avi
  • Start date Start date
A

avi

Hello,

I try to populate a 2 dims array in VBA with a 2 dims created in
DLL(via VB6). Declaring in Vb6 the array as public is rejected.

Help please

Avi
 
A bit vague on detail, I gess you are trying to make an array Public in a
class module of your dll. Can't do that in VB or VBA.

One of many ways -

' Class1, public class in the dll or simply in VBA for testing
Dim mnArr(0 To 5) As Long

Public Function PopArray(n As Long)
For i = 0 To UBound(mnArr)
mnArr(i) = n * i
Next
End Function

Public Function GetArray(theArray() As Long)
theArray = mnArr
End Function


' normal module in VB or VBA
Dim c As Class1

Sub Test()

FillArray
GetArray
ClearUp

End Sub

Sub FillArray()
If c Is Nothing Then Set c = New Class1
c.PopArray 10
End Sub

Sub GetArray()
Dim anArray() As Long
If c Is Nothing Then Exit Sub

c.GetArray anArray

For i = LBound(anArray) To UBound(anArray)
Debug.Print i, anArray(i)
Next

End Sub

Sub ClearUp()
Set c = Nothing ' destroy the class (and/or quit the dll)
End Sub

Regards,
Peter T
 
Hello peter,

Thanks again for your help.

As it seems quite problematic and difficult to reference everything in
VB6, i decided to rewrite all my VBA code in VB6 with only a reference
to the active workbook, as it is an add-in.

The decision seems very promising for the moment

Thanks again
Avi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top