Log Function

See Also3MAKGDE              Example103F6S2>Low

Returns the natural logarithm of a number.




The argument number can be any valid numeric expression71RISN that results in a value greater than 0.  The natural logarithm is the logarithm to the base e.  The constant e is approximately 2.718282.

You can calculate base-n logarithms for any number x by dividing the natural logarithm of x by the natural logarithm of n as follows:

Logn(x) = Log(x) / Log(n)


The following example illustrates a Function procedure that calculates base-10 logarithms:

   Static Function Log10(X)

      Log10 = Log(X) / Log(10#)

   End Function

See Also

Exp FunctionLANEXP

Math FunctionsEK0VY1

Derived Math Functions3KO5YS8

Log Function Example

The example calculates the value of e, then uses the Log function to calculate the natural logarithm of e to the first, second, and third powers.  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 I, Msg, NL                        ' Declare variables.

   NL = Chr(13) & Chr(10)                ' Define newline.

   Msg = Exp(1) & NL

   For I = 1 To 3                        ' Do three times.

      Msg = Msg & Log(Exp(1) ^ I) & NL

   Next I

   MsgBox Msg                            ' Display message.

End Sub