View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Making array in DLL available in VBA?

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


"avi" wrote in message
ps.com...
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