我学习工薪阶层。请帮我解决这个问题。
我在Excel中准备了Class:
班级名称"复杂"
Option Explicit
Public Re As Double 'Real
Public Im As Double 'Imaginary
Public Function CCAdd(ParamArray Complex1() As Variant) as Complex
Dim i As Variant
Dim ZXC As Complex
Set ZXC = New Complex
For i = 0 To UBound(Complex1) 'Numer of arguments passed to the function
If Not IsMissing(Complex1(i)) Then 'Omit arguments which don't exist
If TypeName(Complex1(i)) = "Complex" Then ' Check is it Complex
ZXC.Re = Complex1(i).Re + ZXC.Re
ZXC.Im = Complex1(i).Im + ZXC.Im
End If
End If
Next i
Set Add = ZXC
Set ZXC = Nothing
End Function
在我放置的模块中:
sub asd()
Dim K As Complex
Dim Z As Complex
Dim A As Complex
Set K = New Complex
Set Z = New Complex
Set A = New Complex
K.Re = 1
K.Im = 2
Z.Re = 3
Z.Im = 4
A = K.CCAdd(K, Z)
end sub
执行函数CCAdd后,我将错误传递给" A"。怎么解决这个?也许函数不能通过非标准类型的数据。
答案 0 :(得分:3)
在Complex类中,这一行:
Set Add = ZXC
需要:
Set CCAdd = ZXC
然后在模块中,你只需要:
Sub asd()
Dim K As Complex
Dim Z As Complex
Dim A As Complex
Set K = New Complex
Set Z = New Complex
K.Re = 1
K.Im = 2
Z.Re = 3
Z.Im = 4
Set A = K.CCAdd(K, Z)
End Sub
因此,您不需要使用Set A = New Complex
,但在将Set
功能分配给CCAdd
时,您需要使用 let priority = DISPATCH_QUEUE_PRIORITY_DEFAULT
dispatch_async(dispatch_get_global_queue(priority, 0)) {
dispatch_async(dispatch_get_main_queue()) {
self.performSegueWithIdentifier("ShowNextView", sender: nil)
}
}
。