Function Prop_poli(ByVal x As Variant) As Variant 'EXAMPLE OF SUB: HOW TO CALL THE FUNCTION Prop_poli 'Sub test() 'Dim x() As Variant 'Dim out As Variant ''input points 'ReDim x(1 To 10, 1 To 2) As Variant ' ''Secção em canal 'x(1, 1) = -1.8 'x(1, 2) = 2.4552 'x(2, 1) = -2.1 'x(2, 2) = -0.5448 'x(3, 1) = -2.1 'x(3, 2) = -1.1448 'x(4, 1) = 2.1 'x(4, 2) = -1.1448 'x(5, 1) = 2.1 'x(5, 2) = -0.5448 'x(6, 1) = 1.8 'x(6, 2) = 2.4552 'x(7, 1) = 1.5 'x(7, 2) = 2.4552 'x(8, 1) = 1.5 'x(8, 2) = -0.5448 'x(9, 1) = -1.5 'x(9, 2) = -0.5448 'x(10, 1) = -1.5 'x(10, 2) = 2.4552 ' 'out = Prop_poli(x) ' 'End Sub Dim n_pts As Integer Dim i As Integer Dim Area As Double Dim Cx As Double Dim Cy As Double Dim Ix As Double Dim Iy As Double Dim Ixy As Double Dim PROP_OUT As Variant n_pts = UBound(x, 1) Area = 0 Cx = 0 Cy = 0 Ix = 0 Iy = 0 Ixy = 0 For i = 1 To (n_pts - 1) Area = Area + (x(i, 1) * x(i + 1, 2) - x(i + 1, 1) * x(i, 2)) Cx = Cx + (x(i, 1) + x(i + 1, 1)) * (x(i, 1) * x(i + 1, 2) - x(i + 1, 1) * x(i, 2)) Cy = Cy + (x(i, 2) + x(i + 1, 2)) * (x(i, 1) * x(i + 1, 2) - x(i + 1, 1) * x(i, 2)) Ix = Ix + (x(i, 2) ^ 2 + x(i, 2) * x(i + 1, 2) + x(i + 1, 2) ^ 2) * (x(i, 1) * x(i + 1, 2) - x(i + 1, 1) * x(i, 2)) Iy = Iy + (x(i, 1) ^ 2 + x(i, 1) * x(i + 1, 1) + x(i + 1, 1) ^ 2) * (x(i, 1) * x(i + 1, 2) - x(i + 1, 1) * x(i, 2)) Ixy = Ixy + (x(i, 1) * x(i + 1, 2) + 2 * x(i, 1) * x(i, 2) + 2 * x(i + 1, 1) * x(i + 1, 2) + x(i + 1, 1) * x(i, 2)) * (x(i, 1) * x(i + 1, 2) - x(i + 1, 1) * x(i, 2)) Next i = n_pts Area = Area + (x(i, 1) * x(1, 2) - x(1, 1) * x(i, 2)) Cx = Cx + (x(i, 1) + x(1, 1)) * (x(i, 1) * x(1, 2) - x(1, 1) * x(i, 2)) Cy = Cy + (x(i, 2) + x(1, 2)) * (x(i, 1) * x(1, 2) - x(1, 1) * x(i, 2)) Ix = Ix + (x(i, 2) ^ 2 + x(i, 2) * x(1, 2) + x(1, 2) ^ 2) * (x(i, 1) * x(1, 2) - x(1, 1) * x(i, 2)) Iy = Iy + (x(i, 1) ^ 2 + x(i, 1) * x(1, 1) + x(1, 1) ^ 2) * (x(i, 1) * x(1, 2) - x(1, 1) * x(i, 2)) Ixy = Ixy + (x(i, 1) * x(1, 2) + 2 * x(i, 1) * x(i, 2) + 2 * x(1, 1) * x(1, 2) + x(1, 1) * x(i, 2)) * (x(i, 1) * x(1, 2) - x(1, 1) * x(i, 2)) Area = Area / 2 Cx = Cx / (6 * Area) Cy = Cy / (6 * Area) Ix = Ix / 12 Iy = Iy / 12 Ixy = Ixy / 24 'montagem da saida ReDim PROP_OUT(1 To 6) As Variant PROP_OUT(1) = Area PROP_OUT(2) = Cx PROP_OUT(3) = Cy PROP_OUT(4) = Ix PROP_OUT(5) = Iy PROP_OUT(6) = Ixy Prop_poli = PROP_OUT End Sub