Hi all, I'm relatively new to VB but I know that an overflow occurs when you try to make a variable be too high or low for what you've prepared it for, e.g. 300 when you've prepared it for use as a byte.
Here's what happening - I am trying to make a function which 'decodes' a color number (I mean, the kind of values object.BackColo r can be, and which the RGB() function gives back) into its separate R, G and B values each from 0 to 255.
But here's the problem. To do that, I use this code:
(This is the part of it which is causing an overflow)
CurrentColumn is sometimes needed to be higher than 255, that's why I didn't make it a 'byte' type.
When I test this (i.e. F5, not compiling to an EXE) VB says it overflows. Even when I type into the Immediate Window:
it still overflows.
According to this site, a 'long' data type in VB can be up to 2,147,483,647 (which is 10 digits long), and yet 255^3 is only 16,581,375 (8 digits long).
Why does VB overflow when it tries to do this? (Especially why does it also overflow in the Immediate Window?)
Here's what happening - I am trying to make a function which 'decodes' a color number (I mean, the kind of values object.BackColo r can be, and which the RGB() function gives back) into its separate R, G and B values each from 0 to 255.
But here's the problem. To do that, I use this code:
Code:
Dim ColumnValue As Long
Dim CurrentColumn As Integer
For CurrentColumn = 255 To 0 Step -1
ColumnValue = 255 * 255 * CurrentColumn 'This is where it overflows
CurrentColumn is sometimes needed to be higher than 255, that's why I didn't make it a 'byte' type.
When I test this (i.e. F5, not compiling to an EXE) VB says it overflows. Even when I type into the Immediate Window:
Code:
?255*255*255
According to this site, a 'long' data type in VB can be up to 2,147,483,647 (which is 10 digits long), and yet 255^3 is only 16,581,375 (8 digits long).
Why does VB overflow when it tries to do this? (Especially why does it also overflow in the Immediate Window?)
Comment