|
|
Title | Calculate logarithms in different bases in Visual Basic 6 |
Description | This example shows how to calculate logarithms in different bases in Visual Basic 6 |
Keywords | log, ln, logarithm, base, log base, calculate, exponent, exponentiation, power |
Categories | Algorithms, Tips and Tricks |
|
|
Visual Basic 6's Log function calculates the natural log of a number. To calculate a log in a different base, use this formula:
Log(N) = Log(N)/Log(Base)
When you enter a number and a base and click the Find Log button, the program calculates the log of the number using that base. It displays the result and then raises the base to the calculated power to verify the result.
|
|
Private Sub cmdCalculate_Click()
Dim num, base, result
num = Val(txtNumber.Text)
base = Val(txtBase.Text)
' Calculate Log(num) in the base.
result = Log(num) / Log(base)
txtResult.Text = Format$(result)
txtVerify.Text = Format$(base ^ result)
End Sub
|
|
|
|
|
|