Cos Function

See Also2R8KGX5              ExampleGU17GM>Low

Returns the cosine of an angle.




The argument angle can be any valid numeric expression71RISN measured in radians.

The Cos function takes an angle and returns the ratio of two sides of a right triangle.  The ratio is the length of the side adjacent to the angle divided by the length of the hypotenuse.

The result lies in the range -1 to 1.

To convert degrees to radians, multiply degrees by Pi/180.  To convert radians to degrees, multiply radians by 180/Pi.  Pi is approximately 3.141593.

See Also

Atn FunctionLANATN

Sin FunctionLANSIN

Tan FunctionLANTAN

Math FunctionsEK0VY1

Derived Math Functions3KO5YS8

Cos Function Example

The example uses Cos to calculate the cosine of an angle with a user-specified number of degrees.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.


Sub Form_Click ()

   Dim Degrees, Msg, Pi, Radians               ' Declare variables.

   Pi = 4 * Atn(1)                             ' Calculate Pi.

   Degrees = InputBox("Enter an angle in degrees.")  ' Get user input.

   Radians = Degrees * (Pi / 180)              ' Convert to radians.

   Msg = "The cosine of a " & Degrees

   Msg = Msg & " degree angle is "

   Msg = Msg & Cos(Radians) & "."

   MsgBox Msg                                  ' Display results.

End Sub