Aug 8, 2008

Log Function

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > VB Programming

free web hosting

Log Function

kvarnerexpress
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:

CODE
Na = 0
temp = 0
temp1 = 0
rs.MoveFirst
Do
   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.Update
Na = 0
rs.MoveNext
Loop Until rs.EOF



kvarnerexpress

 

 

 


Reply

Galahad
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:
CODE

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:
CODE

Na = 0
temp = 0
temp1 = 0
rs.MoveFirst
Do
  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.Update
Na = 0
rs.MoveNext
Loop Until rs.EOF

 

 

 


Reply

dul
Hi. It is must be a same result. Because mathemathics didn't change. Check your code.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. base 10 logarithm function in vb6 - 24.85 hr back. (1)
  2. visual basic 6.0 log function - 84.56 hr back. (1)
  3. nature of log function - 177.19 hr back. (1)
  4. log() function - 211.64 hr back. (1)
  5. vb6 temp log - 322.31 hr back. (1)
  6. visual basic add log function - 346.03 hr back. (1)
  7. log function code - 364.43 hr back. (1)
  8. vb 6 log function - 390.76 hr back. (1)
  9. vb6 log function details - 412.97 hr back. (1)
  10. vb6 log function - 433.24 hr back. (1)
Similar Topics

Keywords : log, function

  1. Converting To Unix Timestamp
    Function to convert standard time format to Unix timestamp (0)


      Looking for log, function

Searching Video's for log, function
advertisement



Log Function



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE