Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Data Types help ... Overflow errors
I have a formula to calculate a percentage,
dim used, guests as Long, result as single result = (USED / GUESTS)*100 and get the dreaded overflow on data type error on some of the answers. I tried double, variant and decimal in the dim statment. decimal wouldn't even take in the dim. then, I tried, result = round((USED / GUESTS)*100,1) but the syntax gets hung up on the parentheses ... help greatly appreciated. Larry Levinson Talking up to the vocal ... LLevinson*Bloomberg.net (remove the star etc ....) |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Data Types help ... Overflow errors
Hello Larry
Since one of your variables (guests) used in your calculation is declared as Long (that's between -2 147 483 648 and 2 147 483 647) I can hardly see this working because the "result" variable is declared for a lesser value? Try and declare "result" as long? HTH Cordially Pascal "Larry Levinson" a écrit dans le message de news: ... I have a formula to calculate a percentage, dim used, guests as Long, result as single result = (USED / GUESTS)*100 and get the dreaded overflow on data type error on some of the answers. I tried double, variant and decimal in the dim statment. decimal wouldn't even take in the dim. then, I tried, result = round((USED / GUESTS)*100,1) but the syntax gets hung up on the parentheses ... help greatly appreciated. Larry Levinson Talking up to the vocal ... LLevinson*Bloomberg.net (remove the star etc ....) |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Data Types help ... Overflow errors
Does used or guests exceed figure 2,147,483,647 (i.e. two billions and something)? If not then can result exceed E+38 or can be less than E-45? If not then can guests be zero (0)? Change the code as under and try:- Dim used, guests As Long, result As Single If geusts = 0 Then MsgBox "Zero guests will make it divide by zero _ and cause overflow!" Exit Sub End If result = (used / guests) * 100 Sharad *** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Data Types help ... Overflow errors
Overflow ...
"papou" wrote: Hello Larry Since one of your variables (guests) used in your calculation is declared as Long (that's between -2 147 483 648 and 2 147 483 647) I can hardly see this working because the "result" variable is declared for a lesser value? Try and declare "result" as long? HTH Cordially Pascal "Larry Levinson" a écrit dans le message de news: ... I have a formula to calculate a percentage, dim used, guests as Long, result as single result = (USED / GUESTS)*100 and get the dreaded overflow on data type error on some of the answers. I tried double, variant and decimal in the dim statment. decimal wouldn't even take in the dim. then, I tried, result = round((USED / GUESTS)*100,1) but the syntax gets hung up on the parentheses ... help greatly appreciated. Larry Levinson Talking up to the vocal ... LLevinson*Bloomberg.net (remove the star etc ....) Larry Levinson Talking up to the vocal ... LLevinson*Bloomberg.net (remove the star etc ....) |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Data Types help ... Overflow errors
In case anyone finds this, it wasn't actually an overflow error. it
was a divide by zero errror masking as an overflow. thanks. Larry Levinson wrote: Overflow ... "papou" wrote: Hello Larry Since one of your variables (guests) used in your calculation is declared as Long (that's between -2 147 483 648 and 2 147 483 647) I can hardly see this working because the "result" variable is declared for a lesser value? Try and declare "result" as long? HTH Cordially Pascal "Larry Levinson" a écrit dans le message de news: ... I have a formula to calculate a percentage, dim used, guests as Long, result as single result = (USED / GUESTS)*100 and get the dreaded overflow on data type error on some of the answers. I tried double, variant and decimal in the dim statment. decimal wouldn't even take in the dim. then, I tried, result = round((USED / GUESTS)*100,1) but the syntax gets hung up on the parentheses ... help greatly appreciated. Larry Levinson Talking up to the vocal ... LLevinson*Bloomberg.net (remove the star etc ....) Larry Levinson Talking up to the vocal ... LLevinson*Bloomberg.net (remove the star etc ....) Larry Levinson Talking up to the vocal ... LLevinson*Bloomberg.net (remove the star etc ....) |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How can I hide unused file types from file types list in save dial | Excel Discussion (Misc queries) | |||
Excel 2007 error "some chart types cannot be combined with other chart types. Select a different chart types" | Charts and Charting in Excel | |||
Data types when importing Excel data to SQLServer | Excel Discussion (Misc queries) | |||
Data overflow to second worksheet | Excel Worksheet Functions | |||
VBA Long data type overflow | Excel Programming |