Solved

VBA Excel 2010 error?

Posted on 2016-08-16
3
43 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
  • 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
 
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 45

Expert Comment

by:aikimark
ID: 41778840
Ed

Please accept one or more comments as the solution.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

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.
Use Windows Task Scheduler to print a Word document weekly so your printer ink won't dry out.
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

679 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