Hey I'm rather new to VBA so I'm not exactly adept at error-proofing, so forgive me for any blatantly stupid errors in my code.

Well anyways, i need to write a correlation function in access. I found one and modified it a little, but it won't compile. I am writing it in a new form in Access and it gives me an "invalid qualifier" error every time i call DataOne or DataTwo.

Here's the code:

Public Function Correlation(ByRef DataOne() As Single, ByRef DataTwo() As Single) As Single
Dim AveOne, SDOne, AveTwo, SDTwo, SumOne, SumTwo As Single
Dim DifferenceOne, DifferenceTwo As Single

SumOne = 0
SumTwo = 0
DifferenceOne = 0
DifferenceTwo = 0
AveOne = 0
AveTwo = 0
SDOne = 0
SDTwo = 0

Dim i As Integer

For i = 0 To DataOne.GetLength(0) - 1
SumOne = SumOne + DataOne(i)
SumTwo = SumTwo + DataTwo(i)
Next

AveOne = SumOne / (DataOne.GetLength(0))
AveTwo = SumTwo / (DataTwo.GetLength(0))

For i = 0 To DataOne.GetLength(0) - 1
DifferenceOne = DifferenceOne + (DataOne(i) - AveOne) ^ 2
DifferenceTwo = DifferenceTwo + (DataTwo(i) - AveTwo) ^ 2
Next

'Calculate the standard deviation
SDOne = Math.Sqrt(DifferenceOne / (DataOne.GetLength(0) - 1))
SDTwo = Math.Sqrt(DifferenceTwo / (DataTwo.GetLength(0) - 1))

For i = 0 To DataOne.GetLength(0) - 1
Correlation = Correlation + (((DataOne(i) - AveOne) / SDOne) * ((DataTwo(i) - AveTwo) / SDTwo))
Next

Correlation = Correlation * (1 / (DataOne.GetLength(0) - 1))

End Function



Any help or pointers would be greatly appreciated. My main goal is to get the code to compile, as the "invalid qualifier" error is completely stumping me as DataOne and DataTwo are arguments of the function.
Edit/Delete Message