Sub nn()
Dim Ar()
k = 1.5 '容許誤差
fm = Array(32.2, 44.3, 63, 79.1, 95.2, 111.3) '常數陣列
Set d = CreateObject("Scripting.Dictionary")
For i = 0 To UBound(fm)
If i > 0 Then
ReDim Preserve Ar(s)
Ar(s) = fm(i) - fm(i - 1)
s = s + 1
End If
d(i) = fm(i)
Next
n = Application.Mode(Ar) '最常出現差值
If IsNumeric(n) = False Then
n = 0
MsgBox "無週期訊號"
Exit sub
End If
For i = LBound(fm) + 1 To UBound(fm) - 1
If d(i) - d(i - 1) < n - k Or d(i + 1) - d(i) > n + k Then
d.Remove i
End If
Next
MsgBox Join(d.items, Chr(10))
End Sub