Consulting

Results 1 to 13 of 13

Thread: Solved: Newb to vba need help with trig

  1. #1

    Unhappy Solved: Newb to vba need help with trig

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Application.WorksheetFunction.Acosh(10)

    or

    WorksheetFunction.Acosh(10)

    or

    Application.Acosh(10)
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3

    Ok i have made some progress

    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

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    That is just using it, you have to do something with it, such as

    [vba]

    MsgBox Application.Acosh(10)
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    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!
    Last edited by AmardeepD; 02-14-2008 at 07:00 AM.

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    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.

  8. #8
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Excel's confusing the variable "mid" with the function Mid may be sending 0 as the argument for Cosh, causing the error.

  9. #9
    Ok so i tried changing the variable name and im still getting the same error :s

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    I thought that you wanted Acosh, not Cosh.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  11. #11
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    numele1val = 10 * Log(1 + epsilon * Application.Evaluate("Cosh((" & numele1 & "*" & mid & ")^2)"))
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  12. #12
    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

  13. #13
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •