Overflow

Phoebe
10-03-2001, 04:56 PM
I encountered: error '6': overflow when trying to calculate something:

It's not a data type issue because when calculating I use long, and even when outputing the result to textbox, like below, I still got the error message:

-----------------------------------------------------------
Text2.Text = (((24 * 3600) - (Hour(shiftStart) * 3600) - (Minute(shiftStart) * 60)))
-----------------------------------------------------------

What's up with this? The value of hour(anydate) ranges from 0-23, and the value of minute(anydate) ranges from 0-60.

So?

KesleyK
10-03-2001, 05:01 PM
Try this instead:

Text2.Text = (((24 * CLng(3600)) - (Hour(shiftStart) * CLng(3600)) - (Minute(shiftStart) * 60)))

__________
HOOOaaaaa! Semper Fi!

Phoebe
10-03-2001, 05:08 PM
Thanks a bunch! That works!
Why do I have to convert 3600 to long first, though?

Again, thanks.

Volte
10-03-2001, 05:10 PM
When VB Multiplies, it creates a temp variable, which is an integer, and integers only go up to 32767. I think 3600& may have worked instead of CLng(3600) too.

Phoebe
10-03-2001, 05:16 PM
Got it! I see that I still have a lot to learn.
Thank you, Volteface and KelseyK.

Thinker
10-04-2001, 12:35 PM
Just for information, I believe you can use 3600& to declare the constant
as type long, instead of converting. This might be marginally faster.

I think therefore I am... sometimes right. images/icons/wink.gif

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum