Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inventor VBA Macro Inverse Sine Function

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
AutoDesk_Inventor.
1916 Views, 7 Replies

Inventor VBA Macro Inverse Sine Function

AutoDesk_Inventor.
Participant
Participant

Hi,

 

I am trying to use the Asin function in an Inventor VBA Form Macro but I am getting the following error with Asin highlighted:

 

RichardBall_3-1599562488169.png

Inventor VBA doesn't seem to recognize the Asin function? Do you know what it should be?

 

 

 

 

0 Likes

Inventor VBA Macro Inverse Sine Function

Hi,

 

I am trying to use the Asin function in an Inventor VBA Form Macro but I am getting the following error with Asin highlighted:

 

RichardBall_3-1599562488169.png

Inventor VBA doesn't seem to recognize the Asin function? Do you know what it should be?

 

 

 

 

Labels (3)
7 REPLIES 7
Message 2 of 8

WCrihfield
Mentor
Mentor

Unfortunately, the Math.Asin() function is only defined within vb.net, not in VBA.

If you need to use it, you may have to define your own public function for it within a Module.

Check out these links for alternatives:

VBA Math functions 

VBA Derived Math Functions 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Unfortunately, the Math.Asin() function is only defined within vb.net, not in VBA.

If you need to use it, you may have to define your own public function for it within a Module.

Check out these links for alternatives:

VBA Math functions 

VBA Derived Math Functions 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 8

AutoDesk_Inventor.
Participant
Participant

That's a shame, this macro works perfectly in SW using the Arcsin function, everything else about it works as it should. I wonder why VBA is not identical between SW and Inventor, I thought VBA was VBA regardless.

 

I think my best option now would be to link the macro to an excel file which will carry out the math and then read the answer from that excel file, which isn't ideal but would solve the problem.

0 Likes

That's a shame, this macro works perfectly in SW using the Arcsin function, everything else about it works as it should. I wonder why VBA is not identical between SW and Inventor, I thought VBA was VBA regardless.

 

I think my best option now would be to link the macro to an excel file which will carry out the math and then read the answer from that excel file, which isn't ideal but would solve the problem.

Message 4 of 8

WCrihfield
Mentor
Mentor

That is odd.  Although Excel is an option, I think you could avoid that complication and additional processing cost by simply making your own local function to do the same thing, using the reference data within the second link (above) to the 'derived' math functions within VBA.

Inverse Sine     Arcsin(x) = Atn(X / Sqr(-X * X + 1))

Something like this perhaps:

(you can name it Asin if you want, but I just named it for the example within that link.

Function Arcsin(ByVal oX As Double) As Double
    Dim oVal As Double
    Set oVal = Atn(oX / Sqr(-oX * oX + 1))
    Arcsin = oVal
End Function

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

That is odd.  Although Excel is an option, I think you could avoid that complication and additional processing cost by simply making your own local function to do the same thing, using the reference data within the second link (above) to the 'derived' math functions within VBA.

Inverse Sine     Arcsin(x) = Atn(X / Sqr(-X * X + 1))

Something like this perhaps:

(you can name it Asin if you want, but I just named it for the example within that link.

Function Arcsin(ByVal oX As Double) As Double
    Dim oVal As Double
    Set oVal = Atn(oX / Sqr(-oX * oX + 1))
    Arcsin = oVal
End Function

 

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 8

AutoDesk_Inventor.
Participant
Participant

Hi,

 

I used the local function as originally suggested and it did worked, although not perfectly. When I tested it to calculate different angles I noticed that it wouldn't return a value in all cases, especially if the angle should be 90 degrees.

 

For example the equation is T= dFSin(A)

 

T=Torque (Nm)

d=Distance (m)

F=Force (N)

A=Angle (Degrees)

 

So to calculate the angle I use the following code in the module:

Untitled1.jpg

 

This code in the form:

 

Angle = (ASin(Torque / (Distance * Force))) * (180 / pi)                      '*180/pi to convert Radians into Degrees.

 

When I test with Distance=2, Force=2000 & Torque=2000, I get the correct answer Angle=30. But,

When I input Distance=2, Force=2000 & Torque=4000, I should get the answer Angle=90, but I don't, it's blank.

 

I've also tried your method but unfortunately it didn't work for me:

RichardBall_0-1600069107341.png

 

 

0 Likes

Hi,

 

I used the local function as originally suggested and it did worked, although not perfectly. When I tested it to calculate different angles I noticed that it wouldn't return a value in all cases, especially if the angle should be 90 degrees.

 

For example the equation is T= dFSin(A)

 

T=Torque (Nm)

d=Distance (m)

F=Force (N)

A=Angle (Degrees)

 

So to calculate the angle I use the following code in the module:

Untitled1.jpg

 

This code in the form:

 

Angle = (ASin(Torque / (Distance * Force))) * (180 / pi)                      '*180/pi to convert Radians into Degrees.

 

When I test with Distance=2, Force=2000 & Torque=2000, I get the correct answer Angle=30. But,

When I input Distance=2, Force=2000 & Torque=4000, I should get the answer Angle=90, but I don't, it's blank.

 

I've also tried your method but unfortunately it didn't work for me:

RichardBall_0-1600069107341.png

 

 

Message 6 of 8

JhoelForshav
Mentor
Mentor
Accepted solution

@AutoDesk_Inventor. 

This function for ASin should work 🙂

Sub test()
Dim Angle As Double
Dim Distance As Double
 Distance = 2
Dim Force As Double
 Force = 2000
Dim Torque As Double
Torque = 4000

Angle = (ASin(Torque / (Distance * Force)))
MsgBox Angle
End Sub
    
    Private Function ASin(X As Double) As Double
    Dim Pi As Double
    Pi = 3.14159265358979
      If Abs(X) = 1 Then
        'The VBA Sgn function returns an integer (+1, 0 or -1),
        'representing the arithmetic sign of a supplied number.
        
        ASin = (Sgn(X) * Pi / 2) * 180 / Pi
      Else
        'Atn is the inverse trigonometric function of Tan,
        'which takes an angle as its argument and returns
        'the ratio of two sides of a right triangle
        ASin = Atn(X / Sqr(1 - X ^ 2)) * 180 / Pi
      End If
    End Function

@AutoDesk_Inventor. 

This function for ASin should work 🙂

Sub test()
Dim Angle As Double
Dim Distance As Double
 Distance = 2
Dim Force As Double
 Force = 2000
Dim Torque As Double
Torque = 4000

Angle = (ASin(Torque / (Distance * Force)))
MsgBox Angle
End Sub
    
    Private Function ASin(X As Double) As Double
    Dim Pi As Double
    Pi = 3.14159265358979
      If Abs(X) = 1 Then
        'The VBA Sgn function returns an integer (+1, 0 or -1),
        'representing the arithmetic sign of a supplied number.
        
        ASin = (Sgn(X) * Pi / 2) * 180 / Pi
      Else
        'Atn is the inverse trigonometric function of Tan,
        'which takes an angle as its argument and returns
        'the ratio of two sides of a right triangle
        ASin = Atn(X / Sqr(1 - X ^ 2)) * 180 / Pi
      End If
    End Function
Message 7 of 8

AutoDesk_Inventor.
Participant
Participant

Thanks, it works perfectly!

0 Likes

Thanks, it works perfectly!

Message 8 of 8

_dscholtes_
Advocate
Advocate

Just wanted to mention: The reason the code of @WCrihfield gives an error is because of the 'Set' statement in the 2nd line of code. This statement is not required, since 'oVal' is not an object (it's a double).

Just wanted to mention: The reason the code of @WCrihfield gives an error is because of the 'Set' statement in the 2nd line of code. This statement is not required, since 'oVal' is not an object (it's a double).

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report