Form Code System.OverflowException

  • Thread starter Thread starter bsara
  • Start date Start date
B

bsara

Guest
Hello! I am trying to write a code that allows the user to input an initial and final value, click the calculate button, and be given the sum of the odd numbers and sum of the even numbers. When I tried debugging it, the System.OverflowException error popped up over the sum of the odds line. Can anyone tell me what I am doing wrong? Here's my code:

Public Class UserControl1
Private Sub Calculate_Click(sender As Object, ByVal e As System.EventArgs) Handles Calculate.Click
Dim x As Single
Dim y As Single
Dim i As Integer
Dim sumeven As Integer
Dim sumodd As Integer
x = Val(val_iv.Text)
y = Val(val_fv.Text)
i = x
sumeven = 0
sumodd = 0
Do While i <= y
If i Mod 2 = 0 Then
sumeven += i
Else
sumodd += i
End If
Loop
val_even.Text = Str(sumeven)
val_odd.Text = Str(sumodd)
End Sub
End Class
*I bolded the part where the error message highlights the code.

Continue reading...
 
Back
Top