Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling numbers larger than Long in VBA

I am Currently trying to write some code in VBA to solve a problem from Project Euler. I have been trying to answer a question that requires you to find primes that can be divided into a number that will not fit in a long. Any suggestions as how to handle this problem?

I know I can split the number between two variables and I have done that for addition and subtraction but never division. Any help will be appreciated.

like image 751
Agent389 Avatar asked Dec 03 '09 15:12

Agent389


People also ask

How big can an integer be in Excel VBA?

We got the error “Overflow” because the Integer data type cannot hold anything more than 32767 for positive numbers and -32768 for negative numbers. Type Mismatch Error: Integer data can only hold numerical values between -32768 to 32767.

What is the difference between long and integer in VBA?

Long is a data type in VBA used to store the numeric values. We know that integer also holds numeric values, but Long differs from integers as the data storage range is very big. In the case of the Long data type, we can hold decimal values too. So, it is a built-in data type.

What is the maximum value of an integer type in VBA?

Holds signed 32-bit (4-byte) integers that range in value from -2,147,483,648 through 2,147,483,647.


1 Answers

You can define a Decimal data type (12 Bytes), but only within a variant.

Dim i As Variant

i = CDec(i)

like image 120
Arnon Avatar answered Sep 23 '22 03:09

Arnon