Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I do acos in vb? 2

Status
Not open for further replies.

navyguy

Programmer
Aug 10, 2002
30
US
I have an equation to be calculated in vb that requires me to calculate the acos of a value. There doesn't seem to appear to be an acos function in vb. I heard you can do some trick with atan. Does anyone know that trick or have any suggestions?

Thanks
 
Try this, but be sure that the Value of textbox1 is between -1 and 1:

TextBox2 = Application.WorksheetFunction.Acos(Val(TextBox1))

If you want to result in degrees, multiply it by 180/pi.

TextBox3 = Application.WorksheetFunction.Acos(Val(TextBox1)) * (180 / WorksheetFunction.Pi())

This might do the trick.

If you can't be "The Best", be the best at what you can!!!

Never say Never!!!
Nothing is impossible!!!
 
Hi navyguy,

There is a full list in Excel VBA Help; enter Math in the Search and look at the Math Functions and Derived Math Functions entries.

One caveat: I have seen posts here that suggest they may not all work as advertised, so check them out. I do have enough knowledge to check them out but not the time right now.

Enjoy,
Tony
 
you can also use this formula if you would like...


Arccos(X) = Atn(-X / Sqr(-X * X + 1)) + 2 * Atn(1)

..the atn() function is the arc tangent function, which returns the value in radians not degrees. Therefore..depending on if you needed it in degrees you can do what he did above....

degrees: answer in radians * 180/pi

pi which can be derived from 4*atn(1)

the above way is probably easier...but in vb you dont have those...just showing another option
 
I was assuming that navyguy is using Excel VBA and not VB since he posted his problem in this forum and not any of the numerous VB forums.

Even if he is using VB, I'm sure that someday, someone will be looking for a way to calculate Acos() in VBA.

I hope that we were all able to help him though.

If you can't be "The Best", be the best at what you can!!!

Never say Never!!!
Nothing is impossible!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top