Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleCalculate logarithms in different bases in Visual Basic 2005
DescriptionThis example shows how to calculate logarithms in different bases in Visual Basic 2005
Keywordslog, ln, logarithm, base, log base, calculate, exponent, exponentiation, power, VB.NET
CategoriesAlgorithms, Tips and Tricks
 
Visual Basic .NET's Math.Log function calculates the natural log of a number. Its Math.Log10 calculates the logarithm in base 10. 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 btnFindLog_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles btnFindLog.Click
    Dim num As Double = Val(txtNumber.Text)
    Dim base As Double = Val(txtBase.Text)
    Dim result As Double = Math.Log(num) / Math.Log(base)
    txtResult.Text = result.ToString()
    txtVerify.Text = (base ^ result).ToString()
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated