Solved

Arithmetic operation resulted in an overflow.

Posted on 2014-02-28
7
380 Views
Last Modified: 2014-02-28
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
Comment
Question by:runnerjp2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 39894375
Use Long instead of Integer as the data type
0
 

Author Comment

by:runnerjp2005
ID: 39894391
I seem to get the same error
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 39894396
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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 52

Expert Comment

by:Carl Tawn
ID: 39894400
Can you post samples of some input values that cause the overflow?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39894477
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
 

Author Closing Comment

by:runnerjp2005
ID: 39894596
Walked through it and found i had 0 0/0*0 cant be done :) thanks
0
 
LVL 40
ID: 39895731
It can be done, but by putting the result in a Double, which is able to record an infinite.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question