简体   繁体   中英

VBA function syntax

I am writing functions with the following equation:

  1. P = 10 ^ (A - B9 / ( T + C ))
  2. Z = C * Exp ( -k * t)

I am using the following syntax:

Answer 1:

Function P(a As Integer, b As Integer, c As Integer, t As Integer) As Integer
    P = (10 ^ a) / 10 ^ (b / (t + c))
End Function

Answer 2:

Function Z(c As Integer, k As Integer, t As Integer) As Integer
    Z = c / Exp(-k * t)
End Function

The answers are not coming out as accurate.

Please let me know where I am lacking.

The equations are different from the original, you should also post the expected result from certain numbers, try this:

Function P(a As Integer, b As Integer, c As Integer, t As Integer) As Integer
    P = 10 ^ (a - b / (t + c))
End Function

Function Z(c As Integer, k As Integer, t As Integer) As Integer
    Z = c * Exp(-k * t)
End Function

Also you must take into account the max value that holds the Integer that is: 32767 so the program will overflow when that variable exceeds that value, you can read more about data limits here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM