Results 1 to 2 of 2
  1. #1
    registoni is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    13

    calculation of geometric mean from values in textfields: error

    Hi,


    I have a simple code which looks up at prev. 4 year financials which are stored in unbound textfields (tb0, tb1, tb2, tb3; all as strings) in the current opened form and calculates geometric mean from them:
    Code:
    ' calculate geometric growth averages rates
    
    
     Dim xtemp01 As Double
     Dim xtemp02 As Double
     Dim xtemp03 As Double
     Dim xtemp04 As Double
     Dim xtemp05 As Double
     
    
    
     xtemp01 = ((Me(tb1).Value / Me(tb0).Value - 1))
     
     xtemp02 = ((Me(tb2).Value / Me(tb1).Value - 1))
     
     xtemp03 = ((Me(tb3).Value / Me(tb2).Value - 1))
     
     xtemp04 = (xtemp01 * xtemp02 * xtemp03)
     
     xtemp05 = (xtemp04) ^ (1 / 3)
     
      
     Me(textboxname).Value = Round(xtemp05, 0)
    on this line xtemp05 = (xtemp04) ^ (1 / 3) it report an error RUNTIME ERROR 5: Invalid procedure call or argument.
    What I am doing wrong?
    UPDATE: it turns out one of fields have negative value, but I am taking cubic root, not a square root. What is wrong with cubic root from negative amount?

  2. #2
    registoni is offline Novice
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    13
    found solution (taken from here)

    but it seems VBA do not accept negative number to the power of any number. when I tried debug.print (-8)^(1/3) in imemdiate window, it return error message.
    Code:
     
     Dim xtemp01 As Double
     Dim xtemp02 As Double
     Dim xtemp03 As Double
     Dim xtemp04 As Double
     Dim xtemp05 As Double
     Dim sign As Integer
     
     xtemp01 = ((Me(tb1).Value / Me(tb0).Value))
     
     xtemp02 = ((Me(tb2).Value / Me(tb1).Value))
     
     xtemp03 = ((Me(tb3).Value / Me(tb2).Value))
     
     xtemp04 = (xtemp01 * xtemp02 * xtemp03)
     
     sign = IIf(xtemp04 >= 0, 1, -1)
    
    
     xtemp05 = (sign * Abs(xtemp04) ^ (1 / 3)) -1
    Last edited by registoni; 02-26-2014 at 01:15 AM. Reason: corrected formula for geometric mean. silly mistake.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-01-2013, 05:45 PM
  2. Calculation Field in table vs Query calculation
    By Leonidsg in forum Database Design
    Replies: 18
    Last Post: 02-28-2013, 09:38 PM
  3. Replies: 9
    Last Post: 02-02-2012, 04:59 AM
  4. Replies: 21
    Last Post: 12-29-2010, 01:30 PM
  5. Calculation error
    By wasim_sono in forum Forms
    Replies: 1
    Last Post: 03-26-2009, 02:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums