Large number

ramsee

New Member
Joined
Dec 9, 2008
Messages
36
Hi ,

I am getting an error when I try to do a calculation similar to this in VBA :

if 15,859,698,666,321 mod 258,256,639 = 0 then x = 0.

Getting a message as Stack Overflow. would be grateful to anyhelp from you guys. I am sorry if this has been answered before or sounds silly.

-RAM
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
what type of variable have you declared your number as?

Stack overflow is because a value is exceeding the maximum size for its data type

try declaring it as a double
 
Upvote 0
How have you declared x or the other number variables? They should be a Double in this situation. Also, you didn't use commas in the number you typed did you?

Denis
 
Upvote 0
Hello Denis,

No I didnt type the Commas, and I tied with data types double and even with currency but to no success. 600851475143 : this is the exact number i tried.

Regards
Ram.
 
Upvote 0
The Mod function won't work with numbers larger than a long integer. You'll have to write your own function for doubles.
 
Upvote 0
Strangely enough, but following code gives error:
Code:
[COLOR="Blue"]Sub[/COLOR] Overflow()
    MsgBox 15859698666321# [COLOR="Blue"]Mod[/COLOR] 2
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0
Yes, digits that more than long generate error:
Code:
[COLOR="Blue"]Sub[/COLOR] Overflow()
    [COLOR="Blue"]Dim[/COLOR] d#
    d = 3000000000
    MsgBox TypeName(d)
    MsgBox d [COLOR="Blue"]Mod[/COLOR] 2
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0
Strangely enough, but following code gives error:
Code:
[COLOR=blue]Sub[/COLOR] Overflow()
    MsgBox 15859698666321# [COLOR=blue]Mod[/COLOR] 2
[COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]

That's because the Mod function is trying to convert 15859698666321 to a long integer and can't.
 
Upvote 0
Thanks Andrew for the Solution , I would try to work my problem with a function as you recommended.

@Baitmaster: Sorry I accidentally closed the workbook without saving so I lost the code :( .
 
Upvote 0

Forum statistics

Threads
1,224,541
Messages
6,179,418
Members
452,912
Latest member
alicemil

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top