VBA对象模块必须实现〜?

时间:2015-03-31 19:17:11

标签: vba

我创建了两个类,一个是另一个的接口。每当我尝试实例化Transition_Model时,我得到:

  

编译错误:对象模块需要为接口'〜'

实现'〜'

据我所知,实现类应该有所有公共子,函数和&的副本。属性。所以我不明白这里的问题是什么?

已经看到类似的问题,但要么他们引用actual Sub,要么他们包括other complications让答案太复杂,我无法理解。

另请注意,我尝试将Transition_Model的Subs更改为Private并在子名称前添加'IModel_'(就像我链接的第二个问题中的顶部答案)但我仍然收到相同的错误。

IModel

Option Explicit
Public Enum Model_Types
      Transition
      Dummy
End Enum
Property Get M_Type() As Model_Types
End Property
Sub Run(Collat As Collateral)
End Sub
Sub Set_Params(key As String, value As Variant)
End Sub

Transition_Model

Option Explicit
Implements IModel
Private Transitions As Collection
Private Loan_States As Integer
Private Sub Class_Initialize()
    Set Transitions = New Collection
End Sub
Public Property Get M_Type() As Model_Types
    M_Type = Transition
End Property
Public Sub Run(Collat As Collateral)
    Dim A_Transition  As Transition
    Dim New_Balance() As Double
    Dim Row           As Integer

    For Row = 1 To UBound(Collat.Curr_Balance)
        For Each A_Transition In Transitions
            If A_Transition.Begining = i Then
                New_Balance = New_Balance + Collat.Curr_Balance(Row) * A_Transition.Probability
            End If
        Next A_Transition
    Next
End Sub
Public Sub Set_Params(key As String, value As Double)
    Dim Split_key(1 To 2) As String
    Dim New_Transition As Transition

    Split_key = Split(key, "->")
    Set New_Transition = New Transition

    With New_Transition
        .Begining = Split_key(1)
        .Ending = Split_key(2)
        .Probability = value
    End With

    Transitions.Add New_Transition, key
End Sub

最后我用来测试我的课程

Sub Transition_Model()
    Dim Tested_Class As New Transition_Model
    Dim Collat As New Collateral

    'Test is the model type is correct
    Debug.Assert Tested_Class.M_Type = Transition

    'Test if Model without transition indeed does not affect balances of its collateral
    Collat.Curr_Balance(1) = 0.5
    Collat.Curr_Balance(2) = 0.5

    Tested_Class.Run (Collat)

    Debug.Assert ( _
        Collat.Curr_Balance(1) = 0.5 And _
        Collat.Curr_Balance(2) = 0.5)

End Sub

1 个答案:

答案 0 :(得分:0)

Actaully我连接的第二个问题都有我错过的正确答案。

所有潜艇都需要以“IModel_”开头,并且名称必须与IModel中的名称相匹配。

这是我错过的部分,你不能在子名称中使用下划线。