overFlow...
-
hi, all The following code giving me an overflow error. Please tell me what is wrong in code. Private Sub Command1_Click() Dim x As Long Dim y As Integer y = 10 x = 11025 * y MsgBox x End Sub
VB6 question right?
Dim x As Long
Dim y As Integer
y = 10
x = CLng(11025) * y
MsgBox xWorks fine. But, so does this:
Dim x As Long
Dim y As Integer
y = 10
x = 11025 * CLng(y)
MsgBox xBy using 2 integers as operands, the compiler is presuming that the result will also be an integer. Cheers, Simon "Sign up for a chance to be among the first to experience the wrath of the gods.", Microsoft's home page (24/06/2002)
-
VB6 question right?
Dim x As Long
Dim y As Integer
y = 10
x = CLng(11025) * y
MsgBox xWorks fine. But, so does this:
Dim x As Long
Dim y As Integer
y = 10
x = 11025 * CLng(y)
MsgBox xBy using 2 integers as operands, the compiler is presuming that the result will also be an integer. Cheers, Simon "Sign up for a chance to be among the first to experience the wrath of the gods.", Microsoft's home page (24/06/2002)
-
hi,Simon thanks for your reply but,take this code, it is working fine with out using any type conversion Please.. Dim x As Long Dim y As Integer y = 10 x = 55555 * y MsgBox x
I don't have MSDN for VS6, but the upper limit for an integer is ~32,000, so in your example the "55,555" value is seen as a VB Long. Basically, it's like this: a. long = long * integer b. integer = integer * integer Your example corresponds to "a" and your initial post is like "b". The reason that "b" gave an overflow is that there's the potential for the product of 2 integers to exceed the max value for an integer (the compiler does it's best). HTH Cheers, Simon "Sign up for a chance to be among the first to experience the wrath of the gods.", Microsoft's home page (24/06/2002)
-
I don't have MSDN for VS6, but the upper limit for an integer is ~32,000, so in your example the "55,555" value is seen as a VB Long. Basically, it's like this: a. long = long * integer b. integer = integer * integer Your example corresponds to "a" and your initial post is like "b". The reason that "b" gave an overflow is that there's the potential for the product of 2 integers to exceed the max value for an integer (the compiler does it's best). HTH Cheers, Simon "Sign up for a chance to be among the first to experience the wrath of the gods.", Microsoft's home page (24/06/2002)