Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 123
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 42
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I hide unused file types from file types list in save dial Estra Q Excel Discussion (Misc queries) 1 December 17th 09 12:36 PM
Excel 2007 error "some chart types cannot be combined with other chart types. Select a different chart types" roadsidetree Charts and Charting in Excel 15 June 2nd 09 10:53 AM
Data types when importing Excel data to SQLServer [email protected] Excel Discussion (Misc queries) 1 September 27th 06 12:48 PM
Data overflow to second worksheet jv Excel Worksheet Functions 0 March 30th 06 06:06 PM
VBA Long data type overflow Jean Stax Excel Programming 4 November 15th 03 03:48 PM


All times are GMT +1. The time now is 08:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"