试图创建一个简化比率的函数(存储为长度为2的数组,索引0为分子,索引1为分母)。当传入的值是对象属性时,此函数给我一个错误。
功能如下:
Function SimplifyRatio(Numerator, Denominator)
Dim i As Integer
Dim PNA() As Integer
i = 0
PNA = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199}
While i < PNA.Length()
If Numerator Mod PNA(i) = 0 And Denominator Mod PNA(i) = 0 Then
Numerator = Numerator / PNA(i)
Denominator = Denominator / PNA(i)
i = 0
End If
i = i + 1
End While
Return {Numerator, Denominator}
End Function
这是包含错误函数调用的方法:
Public Function CalculateRatio()
Dim ratio(1) As Byte
ratio = SimplifyRatio(Gear.Teeth, Pinion.Teeth)
Return ratio
End Function
任何帮助将不胜感激, 此致, KyuSiik