CalcArea Function:
Calculates the area of a triangle, square, rectangle, etc...
Description:
The CalcArea function calculates the area of objects. There are two required arguments: formula and values. The formula argument must be a string and the values argument must be an array. CalcArea always returns a double The following chart displays the acceptable values of the formula and values argument: formula argument (string) | values argument (array) | ---------------------------------------------- | triangle | array(0) = base | | array(1) = height | square | array(0) = side | rectangle | array(0) = side1 | | array(1) = side2 | parallelogram | array(0) = base | | array(1) = height | trapezoid | array(0) = base1 | | array(1) = base2 | | array(2) = height | circle | array(0) = radius | ellipse | array(0) = radius1 | | array(1) = radius2 |
Syntax:
double = CalcArea(formula, values)
Example:
<%
Response.Write CalcArea( "triangle", Array( 100.3, 51.2 ) ) '--- Area of a triangle: base=100.3 height=51.2 '--- CalcArea returns 2567.68
Response.Write CalcArea( "square", Array( 21 ) ) '--- Area of a square: side=21 '--- CalcArea returns 441
Response.Write CalcArea( "rectangle", Array( 12.32, 65.06 ) ) '--- Area of a rectangle: side1=12.32 side2=65.06 '--- CalcArea returns 801.5392
Response.Write CalcArea( "parallelogram", Array( 12.32, 5.56 ) ) '--- Area of a parallelogram: base=12.32 height=5.56 '--- CalcArea returns 68.4992
Response.Write CalcArea( "trapezoid", Array( 45.60778, 564.9849, 6.35484 ) ) '--- Area of a trapezoid: base1=45.60778 base2=564.9849 height=6.35484 '--- CalcArea returns 1940.1093932856
Response.Write CalcArea( "circle", Array( 12.456 ) ) '--- Area of a circle: radius=12.456 '--- CalcArea returns 487.424182327834
Response.Write CalcArea( "ellipse", Array( 45.01, 6.7524 ) ) '--- Area of a ellipse: radius1=45.01 radius2=6.7524 '--- CalcArea returns 954.810193436828
%>
ASP Source Code:
<%
Private Function CalcArea(byVal formula, byVal values) Const Pi = 3.1415926535897932 Dim mth, b, b1, b2, h, r, r1, r2, s, s1, s2 Select Case LCase( formula ) Case "triangle" b = CDbl( values(0) ) h = CDbl( values(1) ) mth = b * h * 0.5 Case "square" s = CDbl( values(0) ) mth = s ^ 2 Case "rectangle" s1 = CDbl( values(0) ) s2 = CDbl( values(1) ) mth = s1 * s2 Case "parallelogram" b = CDbl( values(0) ) h = CDbl( values(1) ) mth = b * h Case "trapezoid" b1 = CDbl( values(0) ) b2 = CDbl( values(1) ) h = CDbl( values(2) ) mth = h / 2 * (b1 + b2) Case "circle" r = CDbl( values(0) ) mth = pi * r ^ 2 Case "ellipse" r1 = CDbl( values(0) ) r2 = CDbl( values(1) ) mth = pi * r1 * r2 End Select mth = CDbl( mth ) CalcArea = mth End Function
%>
|