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
Common Logarithm
Author:
Ashok Agarwal
E-mail:
Click to e-mail author
Submitted:
8/15/2003
Version:
VB6
Compatibility:
VB6
Category:
Mathematics
Views:
10982
This code snippet returns the logarithmic value of a given number with 10 as its base (Common Logarithm)with out using the built-in VB LOG function(it uses e as its base[natural or napierian logarithm]).The accuracy of my LogC function is mostly upto 5 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 = "&LogC" End Sub Private Sub Command1_Click() msgbox LogC(Val(InputBox("Enter a number:"))) End Sub Function LogC(Number as double) 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 If 10 ^ (Len(Str(Int(Number)))-2)= Number then LogC = Len(Str(Int(Number)))-2 Exit Function Else Lg=Len(Str(Int(Number)))-2 For J= 1 to 99999 Lg= Lg + 0.00001 If 10 ^ Lg >= Number Then LogC = Lg Exit Function End If Next J End If End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2023 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement