0
votes

I am trying to write a short trig function wanting to use sine and cosine functions in VB and I am very new to this as it's my first time coding in VB.

See what I'm trying to accomplish below:

Function XXX(HR, HR_RL, abc)

Const PI As Double = "3.141593"

AC = Sqr(HR ^ 2 + HR_RL ^ 2 - 2 * HR * HR_RL * Cos(abc * PI / 180))

VB is complaining about two things Cos and Sqr.

It seems they are both built-in VBA functions, but somehow I can't get them evaluated and as a result, AC variable = empty.

In fact, it doesn't seem that it even goes past "Cos(abc * PI / 180)". If I substitute "Cos(abc * PI / 180)" with a numeric value (just to see where else is another problem), surely enough, now VB complains about "Sqr".

1
What kind of "complaints"? What are your data inputs to the function? Using some random numbers, it seems to run OK here.Ron Rosenfeld
@RonRosenfeld, checking "System" didn't work. There is no complaint. The function just returns 0. In the debug mode, I can hoover over or high-light individual variables or terms. It shows AC=empty. High-lighting "abcPI/180" shows the right calc, but high-lighting "Cos(abcPI/180)" doesn't show anything.Eric
Repeating: What are your data inputs to the function? Edit your question to show that.Ron Rosenfeld
@RonRosenfeld, I don't fully understand you question, but HR, HR_RL, and abc are just numbers. If you are referring to the data type, I think they are variants since I didn't separately declare their types.Eric
And what are those numbers? Did they come from a cell or are you inputting them from another VBA macro?Ron Rosenfeld

1 Answers

0
votes

Go into your VBA Editor menu and select Tools -> References..., then check the System library. It will give you access to all the math functions.

enter image description here