PDA

Click to See Complete Forum and Search --> : overflow by 300 * 300


steve_rm
Jun 3rd, 2002, 05:50 AM
Hello

I wonder if you can help me. l am trying to multipile 300 by 300, and get a overflow error. l have tried using a long, single and double datatype, but l am still getting the same problem.

Many thanks in advance

NotLKH
Jun 3rd, 2002, 09:28 AM
Long works for me.
:confused:


Private Sub Command1_Click()
Dim p1 As Long
Dim p2 As Long
Dim p3 As Long
p1 = 300
p2 = 300
p3 = p1 * p2
MsgBox p3
End Sub

steve_rm
Jun 3rd, 2002, 10:33 AM
That bit of code does work.

If you use this code, you will get a overflow error


Private Sub Command1_Click()

Dim p3 As Long

p3 = 300 * 300
MsgBox p3
End Sub


Do you know why this happens

Many thanks in advance

NotLKH
Jun 3rd, 2002, 12:46 PM
Originally posted by steve_rm
That bit of code does work.

If you use this code, you will get a overflow error


Private Sub Command1_Click()

Dim p3 As Long

p3 = 300 * 300
MsgBox p3
End Sub


Do you know why this happens

Many thanks in advance
This is what help says:


You attempt to use a number in a calculation, and that number is
coerced into an integer, but the result is larger than an integer.
For example:

Dim x As Long
x = 2000 * 365 ' Error: Overflow

To work around this situation, type the number, like this:

Dim x As Long
x = CLng(2000) * 365



Now, as to why MSoft designed it that way, I don't know.
Personally, I think its a design flaw.
-Lou