Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBA Excel 2010 error?

Posted on 2016-08-16
3
Medium Priority
?
64 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 46

Accepted Solution

by:
aikimark earned 2000 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

972 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