将对象从VB.NET COM程序集返回到VBA(Access)的问题

时间:2011-03-15 23:02:01

标签: vb.net vba com

我在VB .NET 2.0中有一个程序集,我试图用来调用web服务。

这将是COM可见,并将结果返回到VBA中的Access。

.NET程序集通过所有测试并完美执行。

从VBA调用方法时,我遇到“对象不支持此属性或方法”错误。

我将其分解为某个正在返回的对象并向.NET DLL添加了一些测试方法。

我想要归还一个“患者”对象。 它看起来像这样(测试它非常简单):

Option Strict On
Option Explicit On

<ComClass(Patient.ClassId, Patient.InterfaceId, Patient.EventsId)> _
Public Class Patient

#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 = "672dfbd9-8f3a-4ba2-a33d-89fef868f2b9"
    Public Const InterfaceId As String = "74a9c54c-4427-4d31-8220-3258ecda345d"
    Public Const EventsId As String = "dc25515e-1bb7-4a66-97d5-270c00d792a9"
#End Region

    Public Sub New()

        MyBase.New()

    End Sub

    Public Property StorePatientID() As Integer
        Get
            Return m_StorePatientID
        End Get
        Set(ByVal value As Integer)
            m_StorePatientID = value
        End Set
    End Property
    Private m_StorePatientID As Integer
End Class

所以就像对象一样简单。

我有一个只返回虚拟记录的方法,只是为了测试它:

Public Function GetPatientTest() As Patient
        Dim patient As New Patient

        patient.StorePatientID = 99

        Return patient
    End Function

由于上述错误而失败。

然而,

此方法成功!

Public Function GetPatientArrayTest() As Patient()

        Dim strings As New List(Of Patient)
        Dim patient As New Patient

        patient.StorePatientID = 99

        strings.Add(patient)

        Return strings.ToArray

    End Function

通过“属性”页面可以看到DLL。 构建到project / bin / debug,总是进行重建。 当我在VBA中查看它时似乎总是使用新方法等进行更新,所以不要认为它正在查看旧版本。

显然没有这些方法的有趣依赖。

真的很挣扎。

编辑:

更新16/03/2011 - 添加了VBA脚本

Public Function FindPatientsTest(ByVal surname As String, ByVal surnameBeginsWith As Boolean, ByVal forename As String, ByVal forenameBeginsWith As Boolean, ByVal dateOfBirth As String)


Dim token As String
token = Login()

Dim patient As SCIStoreWS60.patient
Set patient = New SCIStoreWS60.patient

'// This doesn't work.
'// When adding a "Watch" to the function, I can see it returns an "Object/Patient" and is the correct results
'// When adding a "Watch" to the variable "patient" I can see it is a "Patient/Patient"
patient = sciStore.GetPatientTest()

'// This works fine
Dim something As Variant
something = sciStore.GetPatientArrayTest()

End Function

更新16/03/2011 5分钟后 - 惩罚自己

抱歉,我刚刚完成了它。

我需要“设置”患者变量。

Set patient = sciStore.GetPatientTest()

为什么我不需要为“某事”变体做这件事?

1 个答案:

答案 0 :(得分:1)

所以,是的,您需要Set对象引用,但不需要数组。