所以我有这么多不同的二维数组,它们包含流的不同物理属性(马赫数、温度等)。我需要在 excel 中绘制这些值并计算不同的平均值。这些数组是全局声明的。为此,我曾经为每个数组编写一个子例程,但这不是一个好方法,因为您应该尽可能地保持它的通用性,对吗?
所以我最终得到的是:子例程传递了数组和相应的工作表......
或使用指针?知道如何在其他更高级的编程语言(C++,..)中解决这个问题也会很有趣,因为 vba 不是我选择的武器,但在这种情况下它是必要的。
它会出现“类型不匹配:预期为数组或用户定义类型!”的错误。
当我打电话时,我使用:
Call WriteFlowVariable(ws_meridian_velocity, MeridSpeed(), average_MeridSpeed(), area_average_MeridSpeed(), mass_average_MeridSpeed())
这是子程序:
Sub WriteFlowVariable(ws As Worksheet, FlowVariable() As Double, average_FlowVariable() As Double, area_average_FlowVariable(), mass_average_FlowVariable())
Dim i As Integer
Dim j As Integer
Dim sum_v As Double
Dim FlowVariabledeltaA(1000, 300) As Double
Dim FlowVariabledeltaA_added(1000) As Double
Dim FlowVariabledeltaM(1000, 300) As Double
Dim FlowVariabledeltaM_added(1000) As Double
'write titles of the charts
ws.Cells.Clear
For j = 0 To SecNumber - 1
ws.Cells(1, j + 2).value = (j + 1)
Next j
ws.Cells(1, SecNumber + 2) = "Arithmetic Average"
ws.Cells(1, SecNumber + 3) = "Area Average"
For i = 0 To number_of_axial_positions - 1
sum_v = 0
'Write section number
ws.Cells(i + 2, 1).value = i + 1
'Write value and calculate arithmetic, mass and area average
For j = 0 To SecNumber - 1
ws.Cells(i + 2, j + 2).value = FlowVariable(i, j)
sum_v = sum_v + FlowVariable(i, j)
If j < SecNumber - 1 Then
FlowVariable(i, j) = FlowVariable(i, j) * deltaA(i, j)
FlowVariabledeltaA_added(i) = FlowVariabledeltaA_added(i) + FlowVariabledeltaA(i, j)
FlowVariabledeltaM(i, j) = FlowVariable(i, j) * deltaM(i, j)
FlowVariabledeltaM_added(i) = FlowVariabledeltaM_added(i) + FlowVariabledeltaM(i, j)
End If
Next j
average_FlowVariable(i) = sum_v / SecNumber
'Write arithmetic average to the third last column
ws.Cells(i + 2, SecNumber + 2) = average_FlowVariable(i)
area_average_FlowVariable(i) = FlowVariabledeltaA_added(i) / crosssectionareaInput(i)
'Write area average to the second last column
ws.Cells(i + 2, SecNumber + 3) = area_average_FlowVariable(i)
mass_average_FlowVariable(i) = FlowVariabledeltaM_added(i) / crosssectionareaInput(i)
'Write mass average to the last column
ws.Cells(i + 2, SecNumber + 4) = mass_average_FlowVariable(i)
Next i
End Sub