Why an Overflow Message ?

Can anyone help with the below. I've never sees this before !

Add the following lines of code to a new project and run :-

Dim lngTest As Long
lngTest = 12 * 3600

This produces as "Overflow" which I can only get around with :-

Dim lngTest As Long
lngTest = 3600
lngTest = 12 * lngTest

Wierd or am I being Thick ?

Many Thanks

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

That is wierd.
Interested to know the answer also.
Hi Dave
   Strange behaviour. It seems that it should work.
   It doesn't seem that the variable lngTest is the problem since I get the same overflow error in the Debug window by typing "? 12 * 3600" so I went to msdn help and they say to write the code in the manner below. Lo and behold it works!!!

Dim lngTest As Long
lngTest = 12 * CLng(3600)

Happy New Year


I have tested this thoroughly and have deermined that VB is interpreting the literal 36000 as an INTEGER rather than long. It seems that VB sees 12 (well with the range of integer) and then 36000 (Long integer) and can't decide which way to go with it. Weird.

Good luck!!
Yep. You have to tell VB that 12 is not an integer but a long. Enter it as:

LngTest = 12# * 3600

Since the first arguement in the equation is a long, the entire arguement will be processed as a long. Even tho you explicitly declare LngTest to be long, the equation coerces it into integer as that is all that is on the right side of the assignment.

This is not a "bug", but a "side effect" of how the compiler optimizes and "helps" with implicit typing.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
>12# * 3600
12& * 3600&
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.