Afternoon all
I am kind og new to the concept of COM DLL etc and was hoping someone can help me out.
I have created a COM DLL and reference it in VBA. I have mannaged to declare a new class in VBA and then pass values directly to the sub for further calculations.
However, I have a form as part of the DLL and as such I'd like to call the form from say VBA and then fill in values in the form, as soon as form is complete have the values passed to DLL and in return have calculated values passed to VBA for further processing.
Below is relevant code:
COM DLL:
<ComClass(clsCOM_BlockHole.ClassId, clsCOM_BlockHole.InterfaceId, clsCOM_BlockHole.EventsId)> _
Public Class clsCOM_BlockHole
#Region "COM GUIDs"
Public Const ClassId As String = "f4c2ad73-d1e5-4e33-9365-4de32340604a"
Public Const InterfaceId As String = "b253ab72-1fef-4547-991b-66e12aa7bfc7"
Public Const EventsId As String = "abb90279-7ca5-4814-b8d6-cd830eb921c5"
#End Region
Public Sub New()
MyBase.New()
End Sub
Private dblblockLength As Double
Private dblblockWidth As Double
Private dblblockHeight As Double
Private dblblockVolume As Double
Private dblblockArea As Double
Private dblholeDiameter As Double
Public Sub callForm()
Dim frmBlock As fromBlock
frmBlock = New fromBlock
frmBlock.Show()
End Sub
Public Sub calcBlock(ByVal blockHeight As Double, ByVal blockWidth As Double, _
ByVal blockLength As Double)
dblblockHeight = blockHeight
dblblockLength = blockLength
dblblockWidth = blockWidth
dblblockVolume = dblblockHeight * dblblockLength * dblblockWidth
dblblockArea = 2 * (dblblockHeight * dblblockLength + dblblockLength * dblblockWidth + _
dblblockWidth * dblblockHeight)
If dblblockHeight > dblblockWidth Then
dblholeDiameter = dblblockWidth * 0.9
Else
dblholeDiameter = dblblockHeight * 0.9
End If
End Sub
Public Property holeDiameter() As Double
Get
Return dblholeDiameter
End Get
Set(ByVal value As Double)
dblholeDiameter = value
End Set
End Property
Public Property blockLength() As Double
Get
Return dblblockLength
End Get
Set(ByVal value As Double)
dblblockLength = value
End Set
End Property
Public Property blockWidth() As Double
Get
Return dblblockWidth
End Get
Set(ByVal value As Double)
dblblockWidth = value
End Set
End Property
Public Property blockHeight() As Double
Get
Return dblblockHeight
End Get
Set(ByVal value As Double)
dblblockHeight = value
End Set
End Property
Public Property blockVolume() As Double
Get
Return dblblockVolume
End Get
Set(ByVal value As Double)
dblblockVolume = value
End Set
End Property
Public Property blockArea() As Double
Get
Return dblblockArea
End Get
Set(ByVal value As Double)
dblblockArea = value
End Set
End Property
End Class
DLL Form:
Public Class fromBlock
Inherits System.Windows.Forms.Form
Private Sub btnBlockOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnBlockOK.Click
Dim useDLLBlockHole As ClassLibrary1.clsCOM_BlockHole
useDLLBlockHole = New ClassLibrary1.clsCOM_BlockHole
useDLLBlockHole.calcBlock(txtBlockHeight.Text, txtBlockWidth.Text, txtBlockLength.Text)
End Sub
Private Sub btnBlockCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnBlockCancel.Click
Me.Close()
End Sub
End Class
VBA Code:
Sub useForm()
Dim useDLLClass As ClassLibrary1.clsCOM_BlockHole
Set useDLLClass = New ClassLibrary1.clsCOM_BlockHole
Call useDLLClass.callForm
End Sub