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
Printable View
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
Long works for me.
:confused:
VB Code:
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
That bit of code does work.
If you use this code, you will get a overflow error
Do you know why this happensCode:Private Sub Command1_Click()
Dim p3 As Long
p3 = 300 * 300
MsgBox p3
End Sub
Many thanks in advance
This is what help says:Quote:
Originally posted by steve_rm
That bit of code does work.
If you use this code, you will get a overflow error
Do you know why this happensCode:Private Sub Command1_Click()
Dim p3 As Long
p3 = 300 * 300
MsgBox p3
End Sub
Many thanks in advance
Now, as to why MSoft designed it that way, I don't know.Code: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:
To work around this situation, type the number, like this:
VB Code:
Dim x As Long
x = 2000 * 365 ' Error: Overflow
VB Code:
Dim x As Long
x = CLng(2000) * 365
Personally, I think its a design flaw.
-Lou