【发布时间】:2015-04-14 02:10:21
【问题描述】:
我在使用名为“Spectrum”的自定义类模块时遇到问题
以下代码行应从频谱“A”中减去频谱“B”,直接修改“A”中的私有变量。
A.subtract(B)
但在运行时,我收到“运行时错误'438':对象不支持此属性或方法”
这是来自“Spectrum”自定义类模块的子例程:
Private pYValues(1 TO 10000) as Double
Private pIndex as Integer
Public Sub Subtract (Value as Spectrum)
Dim i as Integer
For i = 1 to pIndex
pYValues(i) = pYValues - Value.YValues(i)
Next i
End Sub
Public Property Get YValues(index as Integer)
YValues = pYValues(index)
End Property
这是我尝试从单独的模块运行的代码的实际 sn-p:
Sub testArrayLoading()
' Create a file dialog object
Dim fd As FileDialog
' Choose destination folder (global resource variable!)
Set fd = Application.FileDialog(msoFileDialogOpen)
fd.Show
' Create a spectrum object
Dim mySpectrum1 As Spectrum
Dim mySpectrum2 As Spectrum
Set mySpectrum1 = New Spectrum
Set mySpectrum2 = New Spectrum
' Populate each spectrum with data
mySpectrum1.Import (fd.SelectedItems(1))
mySpectrum2.Import (fd.SelectedItems(1))
' Subtract one spectrum from the other
mySpectrum1.Subtract (mySpectrum2)
End Sub
我不能在同一个类中使用类对象作为参数吗?还是我应该使用属性而不是子例程?
到目前为止,我已经尝试使用 ByVal 和 ByRef,并将子例程切换到公共属性集。两者都没有为我工作。我想我只是在将自定义类对象作为参数传递的理解方面遗漏了一些东西。
感谢您的帮助,
迈克尔
【问题讨论】:
标签: excel vba parameter-passing custom-type