Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBA Excel 2010 error?

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
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

722 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