Advertisement
elpop

VBA,Beams Design , Structural API functions.

Apr 22nd, 2017
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Public Function kg_superposition_moment_value(dist As Double, W As Double, L As Double, Optional P1 As Double, Optional D1 As Double, Optional P2 As Double, Optional D2 As Double, Optional Mnegtv1 As Double, Optional Mnegtv2 As Double)
  3.     Dim Mcalculated, MPosValue, MNegValue As Double
  4.     MPosValue = 0
  5.     MNegValue = 0
  6.     If dist > L Then
  7.         kg_superposition_moment_value = "Dist Exceed L"
  8.         Exit Function
  9.     End If
  10.     '' -- Calculate Negative Moment Value
  11.    ''1 - ONE NEGATIVE
  12.    If Mnegtv2 <> 0 And Mnegtv1 = 0 Then
  13.         ' Case 1
  14.        MNegValue = (Mnegtv2 * dist) / L
  15.     ElseIf Mnegtv1 <> 0 And Mnegtv2 = 0 Then
  16.         ' Case 2
  17.        MNegValue = (Mnegtv1 * (L - dist)) / L
  18.     Else
  19.         ''TWO ARE ZERO OR TWO AREN'T ZERO
  20.        If Mnegtv2 <> 0 And Mnegtv1 <> 0 Then
  21.             If (Mnegtv2 > Mnegtv1) Then
  22.             'CASE 3
  23.                MNegValue = Mnegtv1 + (((Mnegtv2 - Mnegtv1) * (dist)) / L)
  24.             Else
  25.             'CASE 4
  26.               MNegValue = Mnegtv2 + (((Mnegtv1 - Mnegtv2) * (L - dist)) / L)
  27.             End If
  28.         End If
  29.     End If
  30.     '' -- Calculate Postive Moment Value
  31.    'Parabola Moment
  32.    Mcalculated = (W * L * L) / 8
  33.     MPosValue = (((-Mcalculated) / ((L / 2) * (L / 2))) * ((dist - L / 2) * (dist - L / 2))) + Mcalculated
  34.     'P1 Moment
  35.    If (P1 <> 0) Then
  36.         Mcalculated = P1 * D1 * (L - D1) / L
  37.         If (dist <= D1) Then
  38.         'Point Locate Before vertex
  39.            MPosValue = MPosValue + ((Mcalculated * dist) / D1)
  40.         Else
  41.         'Point Locate After Vertex
  42.          MPosValue = MPosValue + (Mcalculated * (L - dist)) / (L - D1)
  43.         End If
  44.     End If
  45.     'P2 Moment
  46.    If (P2 <> 0) Then
  47.         Mcalculated = P2 * D2 * (L - D2) / L
  48.         If (dist <= D2) Then
  49.         'Point Locate Before vertex
  50.            MPosValue = MPosValue + ((Mcalculated * dist) / D2)
  51.         Else
  52.         'Point Locate After Vertex
  53.          MPosValue = MPosValue + (Mcalculated * (L - dist)) / (L - D2)
  54.         End If
  55.     End If
  56.    
  57.     kg_superposition_moment_value = MNegValue + MPosValue
  58. End Function
  59.  
  60.  
  61. Public Function Kg_get_span_case(W As Double, L As Double, P1 As Double, D1 As Double, P2 As Double, D2 As Double)
  62.   ' CASES
  63.  ' 1 => Ws With NO Concentrated Loads
  64.  ' 2 => Ws With One Concentrated
  65.  ' 3 => Ws With Two Loads [D1 & D2 Before Mid-Span]
  66.  ' 4 => Ws With Two Loads [One Load is at mid-span]
  67.  ' 5 => Ws With Two Loads [One Before & One after mid-span]
  68.  
  69.   If (W = 0) Then
  70.     Kg_get_span_case = 0
  71.         Exit Function
  72.   End If
  73.  
  74.   If P1 = 0 And P2 = 0 Then
  75.   'No Concentrated Loads Exist[Case 1]
  76.    Kg_get_span_case = 1
  77.   ElseIf P1 = 0 Or P2 = 0 Then
  78.   'One Exist [Case 2]
  79.    Kg_get_span_case = 2
  80.   Else
  81.   'Two Loads Exist [3,4,5]
  82.    If (D1 < L / 2 And D2 < L / 2) Or (D1 > L / 2 And D2 > L / 2) Then
  83.         Kg_get_span_case = 3
  84.     ElseIf (D1 <> 0 And D2 = L / 2) Or (D2 <> 0 And D1 = L / 2) Then
  85.         Kg_get_span_case = 4
  86.     ElseIf (D1 > L / 2 And D2 < L / 2) Or (D2 > L / 2 And D1 < L / 2) Then
  87.         Kg_get_span_case = 5
  88.     Else
  89.         MsgBox "Unexpected ERR"
  90.     End If
  91.   End If
  92.  
  93. End Function
  94.  
  95.  
  96. Public Function Kg_get_station_coordinate(Sindex As Integer, BasePoint As Double, W As Double, L As Double, P1 As Double, D1 As Double, P2 As Double, D2 As Double)
  97. Dim X As Double
  98.  
  99. Select Case Sindex
  100. 'Sindex => Index of Point location :1,2,3,4,5,6
  101.    Case 1
  102.         'Nothing Here,Manunally Calculated
  103.    Case 2
  104.         If Kg_get_span_case(W, L, P1, D1, P2, D2) = 1 Then
  105.             Kg_get_station_coordinate = CVErr(xlErrNA)
  106.          Else
  107.             Kg_get_station_coordinate = IIf((D1 < L / 2) And D1 <> 0, BasePoint + D1, CVErr(xlErrNA))
  108.            
  109.         End If
  110.     Case 3
  111.     'Point 3 Get Location
  112.        Select Case Kg_get_span_case(W, L, P1, D1, P2, D2)
  113.         Case 1
  114.             Kg_get_station_coordinate = CVErr(xlErrNA)
  115.         Case 2
  116.         '[IF a>Span/2] D1 [X1 IF X<0]
  117.           X = ((L - D1) * ((P1 * (L - D1) + (W * L * L) / 2) / L - P1 - W * D1)) / ((P1 + W * L - (P1 * (L - D1) + (W * L * L) / 2) / L) + ((P1 * (L - D1) + (W * L * L) / 2) / L - P1 - W * D1))
  118.            If (D1 < L / 2) And (X <> L / 2) Then
  119.                 If X > 0 Then
  120.                     Kg_get_station_coordinate = BasePoint + D1 + X
  121.                 Else
  122.                     Kg_get_station_coordinate = BasePoint + D1
  123.                 End If
  124.            Else
  125.                 Kg_get_station_coordinate = CVErr(xlErrNA)
  126.            End If
  127.         Case 3
  128.             'D2[+X3 IF X<0]
  129.            X = ((L - D2) * ((P1 * (L - D1) + P2 * (L - D2) + (W * L * L) / 2) / L - W * D1 - P1 - W * (D2 - D1) - P2)) / ((P1 + P2 + W * L - (P1 * (L - D1) + P2 * (L - D2) + (W * L * L) / 2) / L) + ((P1 * (L - D1) + P2 * (L - D2) + (W * L * L) / 2) / L - W * D1 - P1 - W * (D2 - D1) - P2))
  130.             If X > 0 Then
  131.                 Kg_get_station_coordinate = BasePoint + D2 + X
  132.             Else
  133.                 Kg_get_station_coordinate = IIf((D2 < L / 2), BasePoint + D2, CVErr(xlErrNA))
  134.             End If
  135.         Case 4
  136.             'D1+X4[IF P1 & P2 Exist < Span/2]
  137.            X = ((L / 2 - D1) * ((P1 * (L - D1) + (W * L * L) / 2 + P2 * L / 2) / L - P1 - W * D1)) / ((P1 + P2 + W * L - (P1 * (L - D1) + (W * L * L) / 2 + P2 * L / 2) / L - W * L / 2 - P2) + ((P1 * (L - D1) + (W * L * L) / 2 + P2 * L / 2) / L - P1 - W * D1))
  138.             MsgBox X
  139.             If D1 < L / 2 And D2 = L / 2 And X < (L / 2 - D1) Then
  140.                 If (X > 0) Then
  141.                       Kg_get_station_coordinate = BasePoint + D1 + X
  142.                 Else
  143.                        Kg_get_station_coordinate = BasePoint + D1
  144.                 End If
  145.            Else
  146.                 Kg_get_station_coordinate = CVErr(xlErrNA)
  147.            End If
  148.            
  149.         Case 5
  150.             'D1[+X5 IF X5>L/2-D1]]
  151.           X = ((D2 - D1) * ((P1 * (L - D1) + (W * L * L) / 2 + P2 * (L - D2)) / L - P1 - W * D1)) / (((P1 * (L - D1) + (W * L * L) / 2 + P2 * (L - D2)) / L - P1 - W * D1) + (P1 + W * L + P2 - (P1 * (L - D1) + (W * L * L) / 2 + P2 * (L - D2)) / L - W * (L - D2) - P2))
  152.             If X > 0 And X < (L / 2 - D1) Then
  153.                 Kg_get_station_coordinate = BasePoint + D1 + X
  154.             Else
  155.                 Kg_get_station_coordinate = CVErr(xlErrNA)
  156.             End If
  157.         End Select
  158.    
  159.     Case 4
  160.         'Mid-Span
  161.        Kg_get_station_coordinate = BasePoint + L / 2
  162.    
  163.    
  164.     Case 5
  165.         Select Case Kg_get_span_case(W, L, P1, D1, P2, D2)
  166.         Case 1
  167.             'NA For distributed
  168.            Kg_get_station_coordinate = CVErr(xlErrNA)
  169.         Case 2
  170.             ' [IF a<Span/2]
  171.             X = (D1 * ((P1 * (L - D1) + (W * L * L) / 2) / L)) / (-((P1 * (L - D1) + (W * L * L) / 2) / L - W * D1) + ((P1 * (L - D1) + (W * L * L) / 2) / L))
  172.             If (D1 > L / 2) And D1 <> L Then
  173.                 If X > 0 Then
  174.                     Kg_get_station_coordinate = BasePoint + X
  175.                 Else
  176.  
  177.                     Kg_get_station_coordinate = BasePoint + D1
  178.                 End If
  179.             Else
  180.                 Kg_get_station_coordinate = CVErr(xlErrNA)
  181.             End If
  182.  
  183.         Case 3
  184.              'X32
  185.            X = (D1 * ((P1 * (L - D1) + P2 * (L - D2) + (W * L * L) / 2) / L)) / (-((P1 * (L - D1) + P2 * (L - D2) + (W * L * L) / 2) / L - W * D1) + ((P1 * (L - D1) + P2 * (L - D2) + (W * L * L) / 2) / L))
  186.            If X > L / 2 And X < D1 Then
  187.                 Kg_get_station_coordinate = BasePoint + X
  188.             Else
  189.                 Kg_get_station_coordinate = CVErr(xlErrNA)
  190.             End If
  191.         Case 4
  192.             'X5 [IF P1 & P2 Exist <Span/2]
  193.            X = ((D2 - D1) * ((P1 * (L - D1) + (W * L * L) / 2 + P2 * (L - D2)) / L - P1 - W * D1)) / ((P1 + P2 + W * L - (P1 * (D2) + (W * L * L) / 2 + P2 * (L - D2)) / L - W * (L - D2) - P2) + ((P1 * (L - D1) + (W * L * L) / 2 + P2 * (L - D2)) / L - P1 - W * D1))
  194.  
  195.             If D1 = L / 2 And D2 > L / 2 Then
  196.                 If (X > 0) Then
  197.                       Kg_get_station_coordinate = BasePoint + D1 + X
  198.                 Else
  199.                        Kg_get_station_coordinate = CVErr(xlErrNA)  'D1 = L/2 [Already calculated]
  200.                End If
  201.            Else
  202.                 Kg_get_station_coordinate = CVErr(xlErrNA)
  203.            End If
  204.            
  205.         Case 5
  206.            'D1[+X5 IF X5<L/2-D1]]
  207.          X = ((D2 - D1) * ((P1 * (L - D1) + (W * L * L) / 2 + P2 * (L - D2)) / L - P1 - W * D1)) / (((P1 * (L - D1) + (W * L * L) / 2 + P2 * (L - D2)) / L - P1 - W * D1) + (P1 + W * L + P2 - (P1 * (L - D1) + (W * L * L) / 2 + P2 * (L - D2)) / L - W * (L - D2) - P2))
  208.              If X > (L / 2 - D1) Then
  209.                 If (X > 0) Then
  210.                       Kg_get_station_coordinate = BasePoint + D1 + X
  211.                 Else
  212.                        Kg_get_station_coordinate = BasePoint + D1
  213.                 End If
  214.            Else
  215.                 Kg_get_station_coordinate = CVErr(xlErrNA)
  216.            End If
  217.         End Select
  218.        
  219.     Case 6
  220.         Select Case Kg_get_span_case(W, L, P1, D1, P2, D2)
  221.         Case 1
  222.             Kg_get_station_coordinate = CVErr(xlErrNA)
  223.         Case 2
  224.             Kg_get_station_coordinate = IIf((D1 > L / 2) And D1 <> L, BasePoint + D1, CVErr(xlErrNA))
  225.         Case 3
  226.             Kg_get_station_coordinate = IIf(D1 > L / 2, BasePoint + D1, CVErr(xlErrNA))
  227.         Case 4
  228.             Kg_get_station_coordinate = IIf(D2 > L / 2, BasePoint + D2, CVErr(xlErrNA))
  229.         Case 5
  230.             Kg_get_station_coordinate = IIf(D2 > L / 2, BasePoint + D2, CVErr(xlErrNA))
  231.         End Select
  232.    Case Else
  233.     Kg_get_station_coordinate = "NOT CALCULATED YET"
  234.    
  235. End Select
  236. End Function
  237.  
  238.  
  239. ''Kg_Sort_Loads is a function used to sort two given loads by their distance and return the first & second load after sorting
  240. ' FOR Example IF we have P1=5t & Distance from left= 2m & P2=4t & Distance = 1m ->The function return P1=4t&A1=1m && P2=5t&A2=2m
  241. ' -------------------function parameters------------------------
  242. 'SortIndex  :: Index of Load|Distance Required
  243. 'PorA       :: Get Force Value or Get force distance
  244. 'P1|P2      :: Forces Value
  245. 'A1|A2      :: Forces Distance
  246. Public Function kg_sort_loads(SortIndex As Integer, PorA As String, P1 As Double, A1 As Double, P2 As Double, A2 As Double)
  247.    
  248.      ''IF NOTHING IS GIVEN
  249.    If P1 = 0 And P2 = 0 Then
  250.     'END Function No sort required
  251.    'Return 0 For all Fields
  252.      kg_sort_loads = 0
  253.      
  254.       'END FUNCTION TO STOP IT FROM CONTINUE
  255.      Exit Function
  256.     End If
  257.    
  258.        
  259.     '' IF THERE IS ONLY ONE FORCE GIVEN
  260.    If P1 = 0 Or P2 = 0 Then
  261.     'P1 or P2 = Zero
  262.        If (P2 = 0 And P1 <> 0) Then
  263.         'Return P1 & A1
  264.            If SortIndex = 1 Then
  265.                 If (PorA = "P") Then
  266.                     kg_sort_loads = P1
  267.                 Else
  268.                     kg_sort_loads = A1
  269.                 End If
  270.             Else
  271.                'IF there is only one force => No Need for Force 2
  272.                kg_sort_loads = 0
  273.             End If
  274.         Else
  275.         'Return P2 & A2
  276.            If SortIndex = 1 Then
  277.                 If (PorA = "P") Then
  278.                     kg_sort_loads = P2
  279.                 Else
  280.                     kg_sort_loads = A2
  281.                 End If
  282.             Else
  283.                'IF there is only one force => Use only one force as min
  284.                kg_sort_loads = 0
  285.             End If
  286.         End If
  287.        Exit Function
  288.     End If
  289.  
  290.    
  291.     ''IF TWO FORCES ARE GIVEN
  292.  
  293.    'FIRST IF USER PUT TWO FORCES WITH SAME DISTANCE -> MAKE THEM ONE
  294.    If P1 <> 0 And P2 <> 0 And A1 = A2 Then
  295.             If SortIndex = 1 Then
  296.                 If (PorA = "P") Then
  297.                     kg_sort_loads = P1 + P2
  298.                 Else
  299.                     kg_sort_loads = A1
  300.                 End If
  301.             Else
  302.                'IF there is only one force => No Need for Force 2
  303.                kg_sort_loads = 0
  304.             End If
  305.         Exit Function
  306.     End If
  307.  
  308.     'Second ,IF Two Forces given, Compare distances
  309.    If A1 < A2 Then
  310.         If SortIndex = 1 Then
  311.             If (PorA = "P") Then
  312.                 kg_sort_loads = P1
  313.             Else
  314.                 kg_sort_loads = A1
  315.             End If
  316.         Else
  317.             If (PorA = "P") Then
  318.                 kg_sort_loads = P2
  319.             Else
  320.                 kg_sort_loads = A2
  321.             End If
  322.         End If
  323.     Else
  324.         If SortIndex = 1 Then
  325.             If (PorA = "P") Then
  326.                 kg_sort_loads = P2
  327.             Else
  328.                 kg_sort_loads = A2
  329.             End If
  330.         Else
  331.             If (PorA = "P") Then
  332.                 kg_sort_loads = P1
  333.             Else
  334.                 kg_sort_loads = A1
  335.             End If
  336.         End If
  337.     End If
  338.    
  339. End Function
  340.  
  341.  
  342. Public Function kg_Elastic_Reaction(Direction As String, SPAN As Double, DISTLOAD As Double, P1 As Double, A1 As Double, P2 As Double, A2 As Double, CantliverMoment As Double)
  343.   Dim R As Double, E1 As Double, E2 As Double
  344.  
  345.     If DISTLOAD <> 0 Then
  346.     '1- Elastic Reaction due to DISTLOAD
  347.         R = DISTLOAD * (SPAN * SPAN * SPAN) / 24
  348.     End If
  349.  
  350.         If Direction = "Right" Then
  351.         'Right [R2]
  352.            '2- Elastic Reaction due to P1 (IF EXIST)
  353.            If P1 <> 0 Then
  354.                 E1 = 0.5 * A1 * ((P1 * A1 * (SPAN - A1)) / SPAN)
  355.                 E2 = 0.5 * (SPAN - A1) * ((P1 * A1 * (SPAN - A1)) / SPAN)
  356.                 R = R + (((E1 * 2 / 3 * A1) + (E2 * (A1 + (1 / 3 * (SPAN - A1))))) / SPAN)
  357.             End If
  358.             If P2 <> 0 Then
  359.             '3- Elastic Reaction due to P2 (IF EXIST)
  360.                E1 = 0.5 * A2 * ((P2 * A2 * (SPAN - A2)) / SPAN)
  361.                 E2 = 0.5 * (SPAN - A2) * ((P2 * A2 * (SPAN - A2)) / SPAN)
  362.                 R = R + (((E1 * 2 / 3 * A2) + (E2 * (A2 + (1 / 3 * (SPAN - A2))))) / SPAN)
  363.             End If
  364.             If CantliverMoment <> 0 Then
  365.                 ' R1-LEFT = 1/3 * M * L
  366.                ' The Sign is +ve As CantliverMoment value paramter is negative So R1 will be negative
  367.                R = R + (1 / 3 * CantliverMoment * SPAN)
  368.             End If
  369.         Else
  370.             'Left[R1]
  371.                If P1 <> 0 Then
  372.                     E1 = 0.5 * A1 * ((P1 * A1 * (SPAN - A1)) / SPAN)
  373.                     E2 = 0.5 * (SPAN - A1) * ((P1 * A1 * (SPAN - A1)) / SPAN)
  374.                     R = R + (((E2 * 2 / 3 * (SPAN - A1)) + (E1 * ((SPAN - A1) + (1 / 3 * A1)))) / SPAN)
  375.                 End If
  376.                 If P2 <> 0 Then
  377.                     E1 = 0.5 * A2 * ((P2 * A2 * (SPAN - A2)) / SPAN)
  378.                     E2 = 0.5 * (SPAN - A2) * ((P2 * A2 * (SPAN - A2)) / SPAN)
  379.                     R = R + (((E2 * 2 / 3 * (SPAN - A2)) + (E1 * ((SPAN - A2) + (1 / 3 * A2)))) / SPAN)
  380.                 End If
  381.                 If CantliverMoment <> 0 Then
  382.                 ' R2-RIGHT = 1/6 * M * L
  383.                ' TODO - IF CANTLIVER IS AT START | NO NEED FOR THIS FOR NOW
  384.                R = R + (1 / 6 * CantliverMoment * SPAN)
  385.                
  386.             End If
  387.         End If
  388.     kg_Elastic_Reaction = R
  389. End Function
  390.  
  391.  
  392. Public Function Kg_Ngtv_Moment_Calculator(Spans_Count As String, rtrn As String, range As range, Cantliver_moment As Double)
  393.        
  394.        Kg_Moment_Calculator = (range.Cells(0))
  395. '      Select Case Spans_Count
  396. '        Case "ONE"
  397. '            Kg_Moment_Calculator = 0
  398. '        Case "ONE-CNTLVR"
  399. '            Kg_Moment_Calculator = Cantliver_moment
  400. '        Case "TWO"
  401. '             Select Case rtrn
  402. '            Case "M1"
  403. '                Kg_Moment_Calculator = (range.Cells(1, 1))
  404. '            Case "Mc"
  405. '
  406. '            End Select
  407. '
  408. '        Case Else
  409. '        '      Kg_Moment_Calculator = "ERROR"
  410. '        End Select
  411. End Function
  412.  
  413. Public Function Kg_Spans_counter(range As range, Last_span_as_cantliver As String)
  414. Dim S1, S2, S3, S4, S5 As Double
  415. S1 = range.Cells(1)
  416. S2 = range.Cells(2)
  417. S3 = range.Cells(3)
  418. S4 = range.Cells(4)
  419. S5 = range.Cells(5)
  420.  
  421.  If (Application.WorksheetFunction.Max(S5, S4, S3, S2) = 0) Then
  422.     If (Last_span_as_cantliver = "YES") Then
  423.       Kg_Spans_counter = "CNTLVR"
  424.     Else
  425.       Kg_Spans_counter = "ONE"
  426.     End If
  427.  ElseIf (Application.WorksheetFunction.Max(S5, S4, S3) = 0) Then
  428.     If (Last_span_as_cantliver = "YES") Then
  429.       Kg_Spans_counter = "ONE-CNTLVR"
  430.     Else
  431.       Kg_Spans_counter = "TWO"
  432.     End If
  433.   ElseIf (Application.WorksheetFunction.Max(S5, S4) = 0) Then
  434.     If (Last_span_as_cantliver = "YES") Then
  435.       Kg_Spans_counter = "TWO-CNTLVR"
  436.     Else
  437.       Kg_Spans_counter = "THREE"
  438.      End If
  439.   ElseIf (Application.WorksheetFunction.Max(S5) = 0) Then
  440.     If (Last_span_as_cantliver = "YES") Then
  441.       Kg_Spans_counter = "THREE-CNTLVR"
  442.     Else
  443.       Kg_Spans_counter = "FOUR"
  444.      End If
  445.   Else
  446.      If (Last_span_as_cantliver = "YES") Then
  447.       Kg_Spans_counter = "FOUR-CNTLVR"
  448.     Else
  449.       Kg_Spans_counter = "FIVE"
  450.      End If
  451.    End If
  452.  
  453. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement