Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
XML RSS Feed
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
 
TitleCalculate logarithms in different bases in Visual Basic 6
DescriptionThis example shows how to calculate logarithms in different bases in Visual Basic 6
Keywordslog, ln, logarithm, base, log base, calculate, exponent, exponentiation, power
CategoriesAlgorithms, 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
 
 
Copyright © 1997-2008 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated