Click here to Skip to main content
15,913,141 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Morning all

I am trying to create a COM dll in VB for use in various programmes, of which Excel is one. I am trying to pass a value to a function in the dll for a calculation and return the result (this is successful), however, I am also trying to do multiple calculations in the dll and then pass these values as an array or something of that sort back to Excel (or any other programme) for further use (this however is NOT successful).

Below are my code snippets, if anyone can please tell me where I am going wrong.

VB Code:
VB
<ComClass(clsLetGet.ClassId, clsLetGet.InterfaceId, clsLetGet.EventsId)> _
Public Class clsLetGet

#Region "COM GUIDs"
    ' These  GUIDs provide the COM identity for this class 
    ' and its COM interfaces. If you change them, existing 
    ' clients will no longer be able to access the class.
    Public Const ClassId As String = "ee7a8265-63b8-4514-82d9-c2c29ffa16ee"
    Public Const InterfaceId As String = "03af471d-f29a-49c2-bcff-bf9287c21c42"
    Public Const EventsId As String = "e3bc02a2-e43a-4d8f-a787-3f69f4ccc2da"
#End Region

    ' A creatable COM class must have a Public Sub New() 
    ' with no parameters, otherwise, the class will not be 
    ' registered in the COM registry and cannot be created 
    ' via CreateObject.
    Public Sub New()
        MyBase.New()
    End Sub

    Private dblOutputValue As Double

    Public Function valueCalculation(ByVal dblFeedValue As Double) As Double
        valueCalculation = dblFeedValue * dblFeedValue
    End Function

    Public Property letgetValue() As Double
        Get
            dblOutputValue = 15
        End Get
        Set(ByVal value As Double)

        End Set
    End Property

End Class


VBA code:
VB
Sub useDLL()
    Dim useGotValue As Double
    Dim newClsDLL As dll_Let_Get.clsLetGet
    Set newClsDLL = New dll_Let_Get.clsLetGet
    MsgBox newClsDLL.valueCalculation(2.25)
    MsgBox newClsDLL.letgetValue
End Sub
Posted
Comments
JacquesGrobler 8-Aug-12 1:08am    
Perfect, works like a charm, thanks

1 solution

Please see that the set your Property
there is some thing wrong in it

VB
Public Property letgetValue() As Double
        Get
            Return dblOutputValue
        End Get
        Set(ByVal value As Double)
            dblOutputValue = value
        End Set
    End Property


the following link maybe useful:
VBA Extend
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900