kvarnerexpress 0 Report post Posted September 5, 2005 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=2Na=1log(N/Na)=0.6931Using scientific calculator:N=2Na=1log(N/Na)=0.30102999566Code: 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
Galahad 0 Report post Posted September 6, 2005 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
dul 0 Report post Posted October 20, 2005 Hi. It is must be a same result. Because mathemathics didn't change. Check your code. Share this post Link to post Share on other sites