When the loop is
For x = 3 to 10
the codes work fine
when i change it to 100, the code gives an eroor
"Arithmetic operation resulted in an overflow."
on the line "If (Result + PreResult) Mod 2 = 0 Then y = y + Result + PreResult"
WHY????
Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim x As Integer, Result As Long, PreResult As Long, oldresult As Long Dim y As Long Result = 2 PreResult = 1 y = 3 For x = 3 To 100 If (Result + PreResult) Mod 2 = 0 Then y = y + Result + PreResult oldresult = PreResult PreResult = Result Result = Result + oldresult Next TextBox1.Text = y End Sub




Reply With Quote