What is the m_lPower2 function doing? Perhaps you could provide
the code for that function.
--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
"hunting" wrote in message
...
Hello everyone,
I am having issues translating something from C++ to VBA due to
overflow.
As soon as I get to the end of this function, the routine dies.
It
calculates a value, and I can get down to the last line in the
function
(End Function) and everything is fine. As soon as I hit F8 one
more
time, it chokes.
I got the function below from vbAccelerator ... it is supposed
to be
able to do unsigned left and right shifts in VBA while avoiding
overflow. If there is something wrong with the function, what
is it? If
not, am I passing a bad argument? Can anyone help? The
m_lPower2(i)
variable is just equal to 2^i for i = 0 to 31.
Public Function RShift(ByVal lThis As Long, ByVal lBits As
Long) As Long
If (lBits <= 0) Then
RShift = lThis
ElseIf (lBits 63) Then
' .. error ...
ElseIf (lBits 31) Then
RShift = 0
Else
If (lThis And m_lPower2(31 - lBits)) = m_lPower2(31 -
lBits) Then
RShift = (lThis And (m_lPower2(31 - lBits) - 1)) *
m_lPower2(lBits) Or m_lPower2(31)
Else
RShift = (lThis And (m_lPower2(31 - lBits) - 1)) *
m_lPower2(lBits)
End If
End If
End Function
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!