我正在嘗試查找數字x的最大主要除數。當x小於10億時,我的代碼可以正常工作,但是當它大於10億時,會發生溢出錯誤,並且調試將突出顯示帶有Mod的行。當數值在數十億或更高時,用VBA中的Mod溢出錯誤
Sub Largest_Divisor()
Dim x As Double
Dim Q As Integer
Q = 0
Dim L() As Double
x = 999999999#
Dim i As Double
For i = 775145 To 3 Step -2
If x Mod i = 0 Then
If IsPrime(i) Then
ReDim Preserve L(Q) As Double
L(Q) = i
Q = Q + 1
End If
End If
Next i
MsgBox (Application.Max(L))
End Sub
什麼人認爲是造成溢出錯誤? –
[vba運行時錯誤6]的可能的重複(http://stackoverflow.com/questions/20936595/vba-run-time-error-6) – RubberDuck