我已经定义了一个类型:
Type JobData
r_j As Integer
End Type
我将一个变量指定为Type JobData:
Dim job_data() As JobData
我写了一个函数:
Function sumReady(a1 As JobData, a2 As Integer) As Integer
sumReady = a1(0).r_j
For j = 1 To job_ct
sumReady = job_data(j).r_j + sumReady
Next
End Function
但是当我尝试调用该函数时,我收到语法错误。
ActiveCell.Offset(0, 4).Value = sumReady(job_data().r_j, job_ct)
(job_ct定义为整数)
我做错了什么?谢谢!
答案 0 :(得分:0)
您使用的数据类型的属性不是错误的实际数据类型,调用应为ActiveCell.Offset(0, 4).Value = sumReady(job_data, job_ct)
答案 1 :(得分:0)
您的函数既指包含参数的变量(a1
)又指JobData
数据类型的实例(job_data
);类似于a2
和job_ct
。您应该参考a1
和a2
,即:
Function sumReady(a1 As JobData, a2 As Integer) As Integer
sumReady = a1(0).r_j
For j = 1 To a2
sumReady = a1(j).r_j + sumReady
Next
End Function