Gasman
Enthusiastic Amateur
- Local time
- Today, 00:26
- Joined
- Sep 21, 2011
- Messages
- 17,428
TRying to help someone on another forum, they were getting overflow when assigning 4692 * 283 to a Long variable.
As you can see from my reply, I could also get that issue, but found a way around it.
Why would this happen? Just curious really?
-----------------------------------------------------
4692*283 = 1,327,836
That still gives me error 6?
yet Long is supposed to be able to contain -2,147,483,648 to 2,147,483,648
If I use lngResult = 2147483640, it accepts it no problem?
This works
As you can see from my reply, I could also get that issue, but found a way around it.
Why would this happen? Just curious really?
-----------------------------------------------------
4692*283 = 1,327,836
That still gives me error 6?
Code:
Sub TestLong()
Dim lngResult As Long
Dim i1 As Integer, i2 As Integer
i1 = 4692
i2 = 283
lngResult = i1 * i2 'Errors here
Debug.Print lngResult
End Sub
If I use lngResult = 2147483640, it accepts it no problem?
This works
Code:
Sub TestLong()
Dim lngResult As Long
Dim i1 As Long, i2 As Long
i1 = 4692
i2 = 283
lngResult = i1 * i2
Debug.Print lngResult
End Sub