Solved

VBA Excel 2010 error?

Posted on 2016-08-16
3
30 Views
Last Modified: 2016-09-06
I'm reducing (trig) angles [-N .. N] for all allowable N down to [-2*Pi .. 2*Pi] using a real number (double) Mod function equivalent:
=====================
Sub RadsModPi2()
Call Init   ' defines all constants; all vars are Double
' Pi2 = 6.28318530717959   a constant
With ThisWorkbook.Worksheets("Sheet1")
  For I = 6 To 294                                                 ' I is integer
    Rads = .Cells(I, 1)
    RadM = Rads - (Pi2 * (Rads \ Pi2))
    .Cells(I, 2) = RadM
    RadM = Rads - (Pi2 * Fix(Rads / Pi2))
    .Cells(I, 3) = RadM
  Next
End With
End Sub
===============
According to MS, both  " r1 - (r2 * (r1 \ r2)) "   and  " r1 - (r2 * Fix(r1 / r2)) "  are real number equivalents to the Integer mod functions, but the former produces consistently inconsistent results. Has anyone seen this before or is the a problem with the code I'm overlooking?

TIA - Ed

 
R1ModR2.png
0
Comment
Question by:Ed-SSA
  • 2
3 Comments
 
LVL 45

Accepted Solution

by:
aikimark earned 500 total points
ID: 41759537
Fix() behaves differently with negative values than Int(), which approximates the \ operator
0
 

Author Comment

by:Ed-SSA
ID: 41760005
Your connecting the dots between Int() and ( \ ) did the trick; Int is 16-bit, Fix is 64-bit.
Thanks for pointing me in the right direction. - Ed
0
 
LVL 45

Expert Comment

by:aikimark
ID: 41778840
Ed

Please accept one or more comments as the solution.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Being an active EE Expert means to get a lot of (E)EMail, as you certainly know. If you are using Outlook, I'll show you how to minimize your inbox contents without losing anything – even improve the experience by changing the Subject line to facili…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now