为什么即使类型似乎匹配,我也会遇到类型不匹配错误?

时间:2021-06-22 22:48:19

So I wrote a program that, simply put, takes in a bunch of info, does some moving of said info then tries to pass in one of the arrays into another function which does some math operations.

所以我编写了一个程序,简单地说,它接收了一堆信息,然后移动一些信息然后尝试将其中一个数组传递给另一个执行某些数学运算的函数。

However, it is saying that there is a type mismatch when I try to call that function (AllODES()). It says it is expecting an array.

但是,当我尝试调用该函数(AllODES())时,它表示存在类型不匹配。它说它期待一个阵列。

Here is the code:

这是代码:

Public Function DetermineVolume(x As Double, xmax As Double, Flows As Range, h As Double, error As Double, temp As Double, diameter As Double, pressure As Double) As Double()

Dim i, j, m As Integer
Dim k(9, 9), Y5(9), Y4(9), Y4Old(9), ka(3), Kc(3), MW(7), rho(7) As Double
Dim delta0(9), delta1(9), delRatio(9) As Double, Rmin, FT, vol_F As Double

For i = 1 To 7                                                      'Moving the input data so it can acutally be used
    Y4(i) = Flows(i) 'mol/s
Next i

Y4(8) = pressure

                                                                            'k(Order #, equation #)
    For j = 1 To 6                                                          'First to 6th order


        For i = 1 To 7
            rho(0) = rho(0) + rho(i) * Y4(i)       'Calculate average density of mixture
            FT = FT + Y4(i)
            vol_F = vol_F + Y4(i) * MW(i) / rho(i)      'Calculating the total volumetric flowrate (m^3/s)
        Next i

        rho(0) = rho(0) / FT

        For i = 1 To 8                         'Calculating all of the k(1) values for eq 1 to 8
            k(j, i) = AllODES(x, Y4, i, j, k, h, temp, diameter, vol_F, rho(0)) 
        Next i 'CODE BUGS OUT HERE AND SAYS Y4 is a type mismatch
    Next j

DetermineVolume = Y4

End Function

Public Function AllODES(ByVal x As Double, Y() As Double, EqNumber As Integer, order As Integer, k() As Double, h As Double, _
 temp As Double, D As Double, vol_F As Double, rho As Double) As Double

'Some math operations are done in here

 AllODES=x

End Function

So my question is as follows:

所以我的问题如下:

What is causing this type mismatch error (because I appear to be passing an array in for an array), and how can I fix this error.

导致此类型不匹配错误的原因(因为我似乎是为数组传递数组),以及如何修复此错误。

Thanks in advance!

提前致谢!

1 个解决方案

#1


2  

You are getting the error because you are passing a Variant array to a function that is expecting a Double array.

您收到错误是因为您正在将Variant数组传递给期望Double数组的函数。

You probably intended to dimension them as follows:

您可能打算按如下方式对它们进行维度:

Dim i As Integer, j As Integer, m As Integer
Dim k(9, 9) As Double, Y5(9) As Double, Y4(9) As Double, Y4Old(9) As Double, ka(3) As Double, Kc(3) As Double, MW(7) As Double, rho(7) As Double
Dim delta0(9) As Double, delta1(9) As Double, delRatio(9) As Double, Rmin As Double, FT As Double, vol_F As Double

#1


2  

You are getting the error because you are passing a Variant array to a function that is expecting a Double array.

您收到错误是因为您正在将Variant数组传递给期望Double数组的函数。

You probably intended to dimension them as follows:

您可能打算按如下方式对它们进行维度:

Dim i As Integer, j As Integer, m As Integer
Dim k(9, 9) As Double, Y5(9) As Double, Y4(9) As Double, Y4Old(9) As Double, ka(3) As Double, Kc(3) As Double, MW(7) As Double, rho(7) As Double
Dim delta0(9) As Double, delta1(9) As Double, delRatio(9) As Double, Rmin As Double, FT As Double, vol_F As Double