VBA 运行时错误 438:对象不支持此 属性 或方法
VBA Runtime error 438: object doesn't support this property or method
我明白了
error 438
尝试将元素添加到变体数组时。你能帮我调试吗?谢谢
Public Function CouponList() As Double
Dim nbCoupons_lg As Integer
Dim counter_lg As Integer
Dim coupons_var As Variant
Dim coupon As Cls_Coupon
nbCoupons_lg = Maturity_db * CouponPeriodicity_db
If (Not nbCoupons_lg = 0) Then
ReDim coupons_var(1 To nbCoupons_lg) As Variant
For counter_lg = 1 To nbCoupons_lg
Set coupon = New Cls_Coupon
coupon.Period_lg = counter_lg
coupon.Value_db = AnnualCouponRate_db * ParValue_db
coupon.PresentValue_db = coupon.Value_db / (1 + AnnualDiscountRate_db) ^ (coupon.Period_lg / Maturity_db)
coupons_var(counter_lg) = coupon
Next counter_lg
End If
CouponList = coupons_var
End Function
假设您有一个 class Party
(就像您的 Coupon
)这样:
Private m_lGuestsNumber As Long
Public Property Get GuestsNumber() As Long
GuestsNumber = m_lGuestsNumber
End Property
Public Property Let GuestsNumber(ByVal lNewValue As Long)
m_lGuestsNumber = lNewValue
End Property
如果你想把Party
类型的不同对象,通过循环放到一个数组中,这是一个很好的方法:
Public Sub TestMe()
Dim myArr() As Variant
Dim cnt As Long
Dim additional As Long: additional = 10
Dim coupon As Party
ReDim myArr(1 To additional)
For cnt = 1 To additional
Set coupon = New Party
coupon.GuestsNumber = cnt * 2
Set myArr(cnt) = coupon
Next cnt
End Sub
现在您可以轻松地将以上内容与您的代码进行交换。它应该工作。
我明白了
error 438
尝试将元素添加到变体数组时。你能帮我调试吗?谢谢
Public Function CouponList() As Double
Dim nbCoupons_lg As Integer
Dim counter_lg As Integer
Dim coupons_var As Variant
Dim coupon As Cls_Coupon
nbCoupons_lg = Maturity_db * CouponPeriodicity_db
If (Not nbCoupons_lg = 0) Then
ReDim coupons_var(1 To nbCoupons_lg) As Variant
For counter_lg = 1 To nbCoupons_lg
Set coupon = New Cls_Coupon
coupon.Period_lg = counter_lg
coupon.Value_db = AnnualCouponRate_db * ParValue_db
coupon.PresentValue_db = coupon.Value_db / (1 + AnnualDiscountRate_db) ^ (coupon.Period_lg / Maturity_db)
coupons_var(counter_lg) = coupon
Next counter_lg
End If
CouponList = coupons_var
End Function
假设您有一个 class Party
(就像您的 Coupon
)这样:
Private m_lGuestsNumber As Long
Public Property Get GuestsNumber() As Long
GuestsNumber = m_lGuestsNumber
End Property
Public Property Let GuestsNumber(ByVal lNewValue As Long)
m_lGuestsNumber = lNewValue
End Property
如果你想把Party
类型的不同对象,通过循环放到一个数组中,这是一个很好的方法:
Public Sub TestMe()
Dim myArr() As Variant
Dim cnt As Long
Dim additional As Long: additional = 10
Dim coupon As Party
ReDim myArr(1 To additional)
For cnt = 1 To additional
Set coupon = New Party
coupon.GuestsNumber = cnt * 2
Set myArr(cnt) = coupon
Next cnt
End Sub
现在您可以轻松地将以上内容与您的代码进行交换。它应该工作。