• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 398
  • Last Modified:

Arithmetic operation resulted in an overflow.

I am getting the error Arithmetic operation resulted in an overflow.

Function setthepercentage(ByVal thegoals As List(Of Integer), ByVal thename As String) As String

        Dim over05 As Integer = 0
        Dim over15 As Integer = 0
        Dim over25 As Integer = 0
        Dim countelements As Integer = 0
        'work out if it is 0.5 - 1,3,4,5,3,2,4,5,

        For Each element As String In thegoals
            'chekc if over 0.5
            countelements = countelements + 1
            If element > 0 Then
                over05 = over05 + 1
                'check if over 1.5
            ElseIf element > 1 Then
                over15 = over05 + 1
                'check if over 2.5
            ElseIf element > 2 Then
                over25 = over05 + 1
            End If

        Next

        over05 = (over05 / countelements) * 100
        If over05 <> "NaN" Then
            Session(thename & "over05") = over05
        End If
        over15 = (over15 / countelements) * 100

        If over15 <> "NaN" Then
            Session(thename & "over15") = over15
        End If

        over25 = (over25 / countelements) * 100

        If over25 <> "NaN" Then
            Session(thename & "over25") = over25
        End If
    End Function

Open in new window


What its supposed to do is set the percentage...  

so if elements number if greater then 0 i added 1 to the tally

 If element > 0 Then
   over05 = over05 + 1
end if

Open in new window

I also count how many times it goes through a loop so

        countelements = countelements + 1

Open in new window

this give me the numbers to work with so:

over05 = (over05 / countelements) * 100

Open in new window


but this gives me the error Arithmetic operation resulted in an overflow.
0
runnerjp2005
Asked:
runnerjp2005
1 Solution
 
AndyAinscowCommented:
Use Long instead of Integer as the data type
0
 
runnerjp2005Author Commented:
I seem to get the same error
0
 
AndyAinscowCommented:
I'd single step through your code (or use a pencil and paper and work through it).  There might be something wrong in the logic.
If it overruns a Long we are talking pretty BIG numbers.
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
Carl TawnSystems and Integration DeveloperCommented:
Can you post samples of some input values that cause the overflow?
0
 
CodeCruiserCommented:
Could the problem be with following conditions?

If over05 <> "NaN" Then

Comment these out and see what happens.

If you still get an error, tell us on which line.
0
 
runnerjp2005Author Commented:
Walked through it and found i had 0 0/0*0 cant be done :) thanks
0
 
Jacques Bourgeois (James Burger)Commented:
It can be done, but by putting the result in a Double, which is able to record an infinite.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now