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:
Inventor VBA doesn't seem to recognize the Asin function? Do you know what it should be?
Solved! Go to Solution.
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:
Inventor VBA doesn't seem to recognize the Asin function? Do you know what it should be?
Solved! Go to Solution.
Solved by JhoelForshav. Go to Solution.
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:
Wesley Crihfield
(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:
Wesley Crihfield
(Not an Autodesk Employee)
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.
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.
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
(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
(Not an Autodesk Employee)
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:
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:
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:
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:
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
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
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
Jhoel Forshav
Download my free Inventor Addin - Hole Projector
LinkedIn | Ideas | Contributions | Blog posts | Website
Thanks, it works perfectly!
Thanks, it works perfectly!
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.