Jump to content
xisto Community
Sign in to follow this  
kvarnerexpress

Log Function

Recommended Posts

Hi all.

I have some prob with log function.
The code below is not working, it returns a false value.
The value is not same with what I calculate using scientific calculator.

Using my program:
N=2
Na=1
log(N/Na)=0.6931

Using scientific calculator:
N=2
Na=1
log(N/Na)=0.30102999566

Code:

Na = 0temp = 0temp1 = 0rs.MoveFirstDo    For column = 1 To rs.Fields.Count - 1        'If rs.Fields(column) <> Null Then        If Not IsNull(rs.Fields(column).Value) Then            Na = Na + 1        End If    Next column    N = rs.Fields.Count - 1    temp = Log(N / Na)    temp1 = Format(temp, "0.0000")    rs2.AddNew    rs2!Na = temp1    rs2.UpdateNa = 0rs.MoveNextLoop Until rs.EOF


kvarnerexpress

Share this post


Link to post
Share on other sites

Yes, I had that same problem once...
In Visual Basic, LOG function is returning a value of natural logarithm (base2), whereas in math LOG specifies Base10 logarithm (or at least I think so). Now, in scientific calculator, you might have noticed LN button, just above the LOG button. If you do that function, you will get the value you want. So, in order to get the numbers you need, use this code or put it in a function:

Public Function MyLog(ByVal Number As Double) As Double  MyLog = Log(Number) / Log(10)End Function

This should give you the values you need, so your code might look something like this:
Na = 0temp = 0temp1 = 0rs.MoveFirstDo   For column = 1 To rs.Fields.Count - 1       'If rs.Fields(column) <> Null Then       If Not IsNull(rs.Fields(column).Value) Then           Na = Na + 1       End If   Next column   N = rs.Fields.Count - 1   temp = Log(N / Na) / Log(10)   temp1 = Format(temp, "0.0000")   rs2.AddNew   rs2!Na = temp1   rs2.UpdateNa = 0rs.MoveNextLoop Until rs.EOF

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.