|
-
Jan 16th, 2006, 03:50 PM
#1
Thread Starter
Addicted Member
God I hate VBA... (Overflow error question)
Why is it that when I type
Into VBA's Immediate Window (in Access) I get an Overflow error? And why is it that when I type
I don't? 
(The numbers are just examples by the way, not special cases)
Using Visual Studio .NET 2005
-
Jan 16th, 2006, 04:09 PM
#2
Re: God I hate VBA... (Overflow error question)
Access assumes that both 240 and 256 as typed have an integer datatype. The product of these two numbers is greater that the max value for the integer datatype but because Access has classified them both as integers it tries to fit the product into an integer- hence the overflow.
If you type the following in the Immediate window, you don't get the error.
Code:
? clng(240) * clng(256)
In your 2nd example the value 65536 is implicittly typed as Long, so the product will also receive a Long type - hence no overflow.
Just another reason why you should always use Option Explicit.
Declan
Don't forget to mark your Thread as resolved.
Take a moment to rate posts that you think are helpful 
-
Jan 17th, 2006, 11:39 AM
#3
Frenzied Member
Re: God I hate VBA... (Overflow error question)
I LOVE VBA! (Though I didn't when I first started!)
You can also type:
? 256& * 333&
The "&" casts the entered number to Type Long, but don't bother trying to look up "&" in the (2003) HelpHeap! I have a note in the margin of "Definitive Guide to Excel VBA" (Kofler) about "use trailing & for Hex" (???) but I've forgotten exactly what that means. It does not mean hex in the above example.
Blessings in abundance,
All the Best,
& ENJOY!
Art . . . . Carlisle, PA . . USA
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|