PDA

View Full Version : Solved: Newb to vba need help with trig



AmardeepD
02-14-2008, 04:57 AM
Ok so im a placement student of engineering and have yet to do vba (have got some experiance with vb though phew!) and have been working on a sort of pet project that they have given me to do whenever they dont have any work for me to actually do. The program essentially just churns through loads of calculations after a specification for a filter is input and simulates components and then gives simulated results in graph format (so its a project that will probably take all my free time for the full year ... expect me to post a lot hehe). I have gotten as far as i can withough hitting any problems but now i have a problem with an inverse hyperbolic function

The function is the Acosh of a number.

I did look in the help and it said the syntax was :

expression.Acosh(Arg1)

where expression is a variable that represents a worksheetfunction object.
I have NO idea what this means!!!

It would help a lot if someone could post some sample code of how to use this syntax or something.
Thanks a lot
AmardeepD :help

Bob Phillips
02-14-2008, 05:26 AM
Application.WorksheetFunction.Acosh(10)

or

WorksheetFunction.Acosh(10)

or

Application.Acosh(10)

AmardeepD
02-14-2008, 05:33 AM
Ok so I have dont that and now when i run the program i get runtime error 1004: Unable to get the Acosh property of the WorksheetFunction class :S

Bob Phillips
02-14-2008, 05:50 AM
That is just using it, you have to do something with it, such as



MsgBox Application.Acosh(10)

AmardeepD
02-14-2008, 06:27 AM
Ok well im using it in the context of a calculation. I have:

numele1val=10*log(1+epsilon*(Application.worksheetfunction.cosh((numele1*mi d)^2)))

*just tried to edit out the space and it isnt even there :S*

and it is still coming up with the error??? :S is there something realy simple im missing out?? Thanks
AmardeepD

P.S. Sorry for being a pain haha!

Bob Phillips
02-14-2008, 06:42 AM
What is long?

What is epsilon?

What is m<space>id?

I would suggest somewhere in there iw where your problem lies.

If they give you work that you are not skilled for because they haven't anything else for you to do, why do they employ you at all?

AmardeepD
02-14-2008, 06:51 AM
sorry not long, mistype thats actually log (the computer i am programming on is currently not connected on the internet), epsilon is a variable and that is mid (another variable i have no idea why its come up as m id as when i edit the space isnt there... :S).

I have other projects to work on that I am capable of doing its just that there is some downtime while waiting for parts to be machined or drawings to go through the drawing office. Im actually an intern with the company for a year and they thought it would be a good project for me to get to grips with the maths/theory and to learn some vba to make myself some useful tools... like i said its not actually part of my job but just something to occupy me during the downtime and help with my learning.

Quite a common philosophy at this company is set you some work on something youve never done before to get you to learn it ... so far it has worked quite well and have learned a lot, i think the idea is learning through practical experiance HAHA.

mikerickson
02-14-2008, 07:02 AM
Excel's confusing the variable "mid" with the function Mid may be sending 0 as the argument for Cosh, causing the error.

AmardeepD
02-14-2008, 07:11 AM
Ok so i tried changing the variable name and im still getting the same error :s

Bob Phillips
02-14-2008, 07:33 AM
I thought that you wanted Acosh, not Cosh.

Bob Phillips
02-14-2008, 07:47 AM
numele1val = 10 * Log(1 + epsilon * Application.Evaluate("Cosh((" & numele1 & "*" & mid & ")^2)"))

AmardeepD
02-14-2008, 07:48 AM
Yes i do, i am using cosh in some calculations as well and must have looked at the wrong one, cosh works fine it just seems to be Acosh which is giving problems.
I am now trying to use Acosh from base mathematical principals and that seems to work and seeing as that is how the worksheet function probably gets it (unless there is some level of prroximation taking place) it should be fine :S

AmardeepD
02-14-2008, 07:54 AM
Ok i used the Application.Evaluate with Acosh and it fixed the problem.

I have no idea why the earlier code is working for cosh but not for acosh as i coppied and pasted them into their respective areas :s

Thanks very much for your help guys :clap: :thumb