编译错误Sub或Function not defined(VBA)

时间:2018-05-27 05:51:48

标签: vba compilation

出现"编译错误:Sub或Function not defined"当我运行代码。我一直在寻找解决方案,但它们都没有用。有人知道请帮助我。我不知道编码这是我的功课。教授给我们这段代码来处理我们实验的数据。 这是我的代码

Function FFTRec(N As Integer, theta As Double, ar() As Double, ai() As Double, tmpr() As Double, tmpi() As Double)
    Dim nh As Integer, j As Integer
    Dim xr, xi, wr, wi, tmp2r(512) As Double, tmp2i(512) As Double

    If N > 1 Then
    nh = N / 2
    For j = 0 To nh - 1
        tmpr(j) = ar(j) + ar(nh + j)
        tmpi(j) = ai(j) + ai(nh + j)
        xr = ar(j) - ar(nh + j)
        xi = ai(j) - ai(nh + j)
        wr = Cos(theta * j)
        wi = Sin(theta * j)
        tmp2r(j) = xr * wr - xi * wi
        tmp2i(j) = xi * wr + xr * wi
    Next j
    Call FFTRec(nh, 2 * theta, tmpr, tmpi, ar, ai)
    Call FFTRec(nh, 2 * theta, tmp2r, tmp2i, ar, ai)
    For j = 0 To nh - 1
        ar(2 * j) = tmpr(j)
        ai(2 * j) = tmpi(j)
        ar(2 * j + 1) = tmp2r(j)
        ai(2 * j + 1) = tmp2i(j)
    Next j
    End If
 End Function
 Public Sub FFT()
    Dim xr(512) As Double, xi(512) As Double, tmpr(512) As Double, tmpi(512) As Double
    Dim pi, wm, theta As Double
    Dim i, Tr, N As Integer
    Dim curStartTime, curEndTime, curFreq As Currency

    i = 0: N = 512: Tr = 6
    pi = WorksheetFunction.pi
    theta = 2 * pi / N

    For i = 1 To N
        xr(i - 1) = Cells(i + Tr - 1, 2): xi(i - 1) = 0
    Next i

    Call QueryPerformanceFreQuency(curFreq)
    Call QueryPerformanceCounter(curStartTime)

    Call FFTRec(N, theta, xr, xi, tmpr, tmpi)

    Call QueryPerformanceCounter(curEndTime)
    Cells(1, 9) = "Processing Time " & CStr((curEndTime - curStartTime) / curFreq) & " Second"

    Cells(Tr - 1, 9) = "xr(i)_FFT": Cells(Tr - 1, 10) = "xi(i)_FFT": Cells(Tr - 1, 11) = "P_FFT"
    For i = 0 To N - 1
        Cells(i + Tr, 9) = xr(i)
     Cells(i + Tr, 10) = xi(i)
    Cells(i + Tr, 11) = Sqr(xr(i) ^ 2 + xi(i) ^ 2)
    Next i
 End Sub

Code

Error

顺便说一句,我不是母语人士。

谢谢。

1 个答案:

答案 0 :(得分:0)

未定义函数QueryPerformanceFrequency。你需要在某个地方定义它。我认为这应该解决它。您可以尝试使用代码here

否则,只需要求您的教授提供QueryPerformanceFrequency

定义的代码