Solved

VBA Excel 2010 error?

Posted on 2016-08-16
3
52 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 Covney
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 46

Accepted Solution

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

Author Comment

by:Ed Covney
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 46

Expert Comment

by:aikimark
ID: 41778840
Ed

Please accept one or more comments as the solution.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

635 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