ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Simple function problem (https://www.excelbanter.com/excel-worksheet-functions/34188-simple-function-problem.html)

headly

Simple function problem
 
Maybe I'm too tired to see the obvious, could somebody explain why this
simple function is producing 0 instead of a result?

Public Function AreaCircle(Radius) As Double
Const conPi As Single = 3.141592
AreaofCircle = conPi * (Radius ^ 2)
End Function

If I run it as a sub procedure it works fine.

TIA

Trevor Shuttleworth

Try:

Public Function AreaofCircle(Radius) As Double
Const conPi As Single = 3.141592
AreaofCircle = conPi * (Radius ^ 2)
End Function

or

Public Function AreaCircle(Radius) As Double
Const conPi As Single = 3.141592
AreaCircle = conPi * (Radius ^ 2)
End Function

Depending on your preference - the function name is different to the
variable

Regards

Trevor


"headly" wrote in message
...
Maybe I'm too tired to see the obvious, could somebody explain why this
simple function is producing 0 instead of a result?

Public Function AreaCircle(Radius) As Double
Const conPi As Single = 3.141592
AreaofCircle = conPi * (Radius ^ 2)
End Function

If I run it as a sub procedure it works fine.

TIA




Bob Phillips

If you used Option Explicit, this would have been obvious to you.

--
HTH

Bob Phillips

"Trevor Shuttleworth" wrote in message
...
Try:

Public Function AreaofCircle(Radius) As Double
Const conPi As Single = 3.141592
AreaofCircle = conPi * (Radius ^ 2)
End Function

or

Public Function AreaCircle(Radius) As Double
Const conPi As Single = 3.141592
AreaCircle = conPi * (Radius ^ 2)
End Function

Depending on your preference - the function name is different to the
variable

Regards

Trevor


"headly" wrote in message
...
Maybe I'm too tired to see the obvious, could somebody explain why this
simple function is producing 0 instead of a result?

Public Function AreaCircle(Radius) As Double
Const conPi As Single = 3.141592
AreaofCircle = conPi * (Radius ^ 2)
End Function

If I run it as a sub procedure it works fine.

TIA







All times are GMT +1. The time now is 01:14 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com