BalbasNiBarabas
New Member
- Joined
- Jun 1, 2020
- Messages
- 5
- Office Version
- 2019
- Platform
- Windows
Hello guys!
Would just like some verification on why am I getting the wrong value/answer to this.
Here's the problem:
If d <= R then:
tank = pi * d ^ 2 / 3 * (3 * R - d)
but if d<=h - r then:
tank = 2 / 3 * pi * R ^ 3 + pi * R ^ 2 * (d - H)
Else:
tank = 4 / 3 * pi * R ^ 3 + pi * R ^ 2 * (H - 2 * R) - pi * (H - R) ^ 2 / 3 * (3 * R - H + d)
Below is my vba code:
Let me know your thoughts.
Thank you!
Would just like some verification on why am I getting the wrong value/answer to this.
Here's the problem:
If d <= R then:
tank = pi * d ^ 2 / 3 * (3 * R - d)
but if d<=h - r then:
tank = 2 / 3 * pi * R ^ 3 + pi * R ^ 2 * (d - H)
Else:
tank = 4 / 3 * pi * R ^ 3 + pi * R ^ 2 * (H - 2 * R) - pi * (H - R) ^ 2 / 3 * (3 * R - H + d)
Below is my vba code:
VBA Code:
Function tank(R As Double, H As Double, d As Double) As Double
Dim pi As Double
pi = WorksheetFunction.pi()
If d <= R Then
tank = pi * d ^ 2 / 3 * (3 * R - d)
ElseIf d <= H - R Then
tank = 2 / 3 * pi * R ^ 3 + pi * R ^ 2 * (d - H)
Else
tank = 4 / 3 * pi * R ^ 3 + pi * R ^ 2 * (H - 2 * R) - pi * (H - R) ^ 2 / 3 * (3 * R - H + d)
End If
End Function
Let me know your thoughts.
Thank you!