LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Overflow when translating from C++ HELP!!

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!
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Translating Dates to a Visual english4518 Excel Worksheet Functions 2 September 10th 09 02:43 AM
Translating Erika Excel Discussion (Misc queries) 0 June 6th 08 03:13 PM
Translating formulas Cameron Excel Discussion (Misc queries) 9 August 3rd 06 11:43 AM
Translating function names dziw Excel Discussion (Misc queries) 2 June 30th 05 04:37 AM
Translating spreadsheet formula to VBA Sheela[_2_] Excel Programming 8 June 6th 05 02:51 AM


All times are GMT +1. The time now is 04:38 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"