Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Logarithm of any Base
Author:
Ashok Agarwal
E-mail:
Click to e-mail author
Submitted:
8/15/2003
Version:
VB6
Compatibility:
VB6
Category:
Mathematics
Views:
16219
This code snippet returns the logarithmic value of a given number with any given base without using the built-in VB LOG function(it uses e as its base[natural or napierian logarithm]). The accuracy of my LogB function is only upto a few digits after decimal. For better accuracy you have to "INCREASE" the final value of the for loop-"J",and also have to "DECREASE" the increment value of variable Lg (Lg = Lg + 1/10 ^ x,where x is a positive integer).But this will result in the slow execution of the program.
Declarations:
'none
Code:
Private Sub Form_Load() Command1.Caption = "&LogB" End Sub Private Sub Command1_Click() Msgbox LogB(Val(InputBox("Enter a number:")),Val(InputBox("Enter Base:"))) End Sub Function LogB(Number as double,Base as integer) as Double Dim Lg as Single If Number <=0 then Err.Raise 5 , , "Logarithms for zero and negitive numbers are not defined" Exit Function End If For I = 0 to Number If Base ^ I = Number then LogB=I Exit Function ElseIf Base ^ I < Number And Base ^ (I+1) > Number then Lg = I For J= 1 to 99999 Lg = Lg + 0.00001 If Base ^ Lg >= Number Then LogB = Lg Exit Function End If NExt J End IF Next I End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement