Pi() function and update statement

Jap@a

New member
Local time
Today, 01:28
Joined
May 9, 2011
Messages
3
Dear all,

I wanted to calculate the volume (of an egg) out of length and the width (measured) according to the following formula volume= (((1/6)* pi* Length* width^2)/1000)

But I don’t get the Sql-script working. First of all this PI() function is not working, second it seems like also the divisions are not really working.

I tried as well in Access as in Sqlite (Manager). But both are not working.

Hereunder what it should look like


UPDATE tableA
SET Volume=(((1/6)* pi* Length* width^2)/1000);

But also easier things like Volume= pi() or Volume = (1/2)Length are not working



So wondering if anybody here could help me out thanks a lot.

Brecht
 
Did you add a function for pi? There is no built-in function for that within Access. You would have to build your own or use something someone else might have created.
 
So that would mean I would have to write such a function in VBA?

Or does anyone here has it already?

Thanks,
Brecht
 
Copy this into a standard module (not form, report or class module but standard module) and name the module basMath.
Code:
Function pi() As Double
    pi = 3.14159265358979
End Function
 
Copy this into a standard module (not form, report or class module but standard module) and name the module basMath.
Code:
Function pi() As Double
    pi = 3.14159265358979
End Function


Bob, shame on you, you left out some of the digits. I believe it goes a lot further to the right.
 
Bob, shame on you, you left out some of the digits. I believe it goes a lot further to the right.
I DID put in more but Access truncated it probably due to the Double's precision. I would have used the Decimal datatype but it isn't available from VBA (at least that I've found).
 
I DID put in more but Access truncated it probably due to the Double's precision. I would have used the Decimal datatype but it isn't available from VBA (at least that I've found).


Thast's right, Double has 14 digits to the right of the decimal.
 
But I belive that will be more than accurate enough for Jap@a. 14 decimal places is smaller than an atom.
 
surprising, you would think there would be a vbPi constant, would you not?
 
Thanks. Makes sense.
 
Code:
Option Explicit
Option Compare Text


Public Declare Function timeGetTime Lib "Winmm.dll" () As Long


Public Sub Test()
    Dim lngI     As Long
    Dim lngStart As Long
    Dim dblPi    As Double
    
    lngStart = timeGetTime()
    For lngI = 1 To 1000000
        dblPi = Pi_1()
    Next lngI
    MsgBox timeGetTime() - lngStart     [color=green]'< 85  nanoseconds per call[/color]


    lngStart = timeGetTime()
    For lngI = 1 To 1000000
        dblPi = Pi_2()
    Next lngI
    MsgBox timeGetTime() - lngStart     [color=green]'< 156 nanoseconds per call[/color]

End Sub


Function Pi_1() As Double

    Pi_1 = 3.14159265358979
    
End Function


Public Function Pi_2() As Double
    [color=green]' This can be found on the web.
    ' It seems strange to me because it seems to be based
    ' on two constants and the Atn function based on a constant.[/color]
    
    Pi_2 = 4 * Atn(1)
    
End Function
 
Hi all,

Thanks all for the replies, and sorry I didn't reply anymore myself, I was a bit busy with other things.

So I think I managed to add this pi() function but still I don't get the update statement running.
Even if I try to run something like:

update Update_test
Set Volume=length*2;

It doesn't work I only get empty values for volume, if a run the same statement in SQLite manager it runs so the statement is fine right? But why doesn't it work in Access?

Thanks again,
B
 
For interest...

Pi = (2143/22)^0.25

(correct to 8 d.p.)
 

Users who are viewing this thread

Back
Top Bottom