Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- Dim Mcalculated, MPosValue, MNegValue As Double
- MPosValue = 0
- MNegValue = 0
- If dist > L Then
- kg_superposition_moment_value = "Dist Exceed L"
- Exit Function
- End If
- '' -- Calculate Negative Moment Value
- ''1 - ONE NEGATIVE
- If Mnegtv2 <> 0 And Mnegtv1 = 0 Then
- ' Case 1
- MNegValue = (Mnegtv2 * dist) / L
- ElseIf Mnegtv1 <> 0 And Mnegtv2 = 0 Then
- ' Case 2
- MNegValue = (Mnegtv1 * (L - dist)) / L
- Else
- ''TWO ARE ZERO OR TWO AREN'T ZERO
- If Mnegtv2 <> 0 And Mnegtv1 <> 0 Then
- If (Mnegtv2 > Mnegtv1) Then
- 'CASE 3
- MNegValue = Mnegtv1 + (((Mnegtv2 - Mnegtv1) * (dist)) / L)
- Else
- 'CASE 4
- MNegValue = Mnegtv2 + (((Mnegtv1 - Mnegtv2) * (L - dist)) / L)
- End If
- End If
- End If
- '' -- Calculate Postive Moment Value
- 'Parabola Moment
- Mcalculated = (W * L * L) / 8
- MPosValue = (((-Mcalculated) / ((L / 2) * (L / 2))) * ((dist - L / 2) * (dist - L / 2))) + Mcalculated
- 'P1 Moment
- If (P1 <> 0) Then
- Mcalculated = P1 * D1 * (L - D1) / L
- If (dist <= D1) Then
- 'Point Locate Before vertex
- MPosValue = MPosValue + ((Mcalculated * dist) / D1)
- Else
- 'Point Locate After Vertex
- MPosValue = MPosValue + (Mcalculated * (L - dist)) / (L - D1)
- End If
- End If
- 'P2 Moment
- If (P2 <> 0) Then
- Mcalculated = P2 * D2 * (L - D2) / L
- If (dist <= D2) Then
- 'Point Locate Before vertex
- MPosValue = MPosValue + ((Mcalculated * dist) / D2)
- Else
- 'Point Locate After Vertex
- MPosValue = MPosValue + (Mcalculated * (L - dist)) / (L - D2)
- End If
- End If
- kg_superposition_moment_value = MNegValue + MPosValue
- End Function
- Public Function Kg_get_span_case(W As Double, L As Double, P1 As Double, D1 As Double, P2 As Double, D2 As Double)
- ' CASES
- ' 1 => Ws With NO Concentrated Loads
- ' 2 => Ws With One Concentrated
- ' 3 => Ws With Two Loads [D1 & D2 Before Mid-Span]
- ' 4 => Ws With Two Loads [One Load is at mid-span]
- ' 5 => Ws With Two Loads [One Before & One after mid-span]
- If (W = 0) Then
- Kg_get_span_case = 0
- Exit Function
- End If
- If P1 = 0 And P2 = 0 Then
- 'No Concentrated Loads Exist[Case 1]
- Kg_get_span_case = 1
- ElseIf P1 = 0 Or P2 = 0 Then
- 'One Exist [Case 2]
- Kg_get_span_case = 2
- Else
- 'Two Loads Exist [3,4,5]
- If (D1 < L / 2 And D2 < L / 2) Or (D1 > L / 2 And D2 > L / 2) Then
- Kg_get_span_case = 3
- ElseIf (D1 <> 0 And D2 = L / 2) Or (D2 <> 0 And D1 = L / 2) Then
- Kg_get_span_case = 4
- ElseIf (D1 > L / 2 And D2 < L / 2) Or (D2 > L / 2 And D1 < L / 2) Then
- Kg_get_span_case = 5
- Else
- MsgBox "Unexpected ERR"
- End If
- End If
- End Function
- 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)
- Dim X As Double
- Select Case Sindex
- 'Sindex => Index of Point location :1,2,3,4,5,6
- Case 1
- 'Nothing Here,Manunally Calculated
- Case 2
- If Kg_get_span_case(W, L, P1, D1, P2, D2) = 1 Then
- Kg_get_station_coordinate = CVErr(xlErrNA)
- Else
- Kg_get_station_coordinate = IIf((D1 < L / 2) And D1 <> 0, BasePoint + D1, CVErr(xlErrNA))
- End If
- Case 3
- 'Point 3 Get Location
- Select Case Kg_get_span_case(W, L, P1, D1, P2, D2)
- Case 1
- Kg_get_station_coordinate = CVErr(xlErrNA)
- Case 2
- '[IF a>Span/2] D1 [X1 IF X<0]
- 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))
- If (D1 < L / 2) And (X <> L / 2) Then
- If X > 0 Then
- Kg_get_station_coordinate = BasePoint + D1 + X
- Else
- Kg_get_station_coordinate = BasePoint + D1
- End If
- Else
- Kg_get_station_coordinate = CVErr(xlErrNA)
- End If
- Case 3
- 'D2[+X3 IF X<0]
- 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))
- If X > 0 Then
- Kg_get_station_coordinate = BasePoint + D2 + X
- Else
- Kg_get_station_coordinate = IIf((D2 < L / 2), BasePoint + D2, CVErr(xlErrNA))
- End If
- Case 4
- 'D1+X4[IF P1 & P2 Exist < Span/2]
- 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))
- MsgBox X
- If D1 < L / 2 And D2 = L / 2 And X < (L / 2 - D1) Then
- If (X > 0) Then
- Kg_get_station_coordinate = BasePoint + D1 + X
- Else
- Kg_get_station_coordinate = BasePoint + D1
- End If
- Else
- Kg_get_station_coordinate = CVErr(xlErrNA)
- End If
- Case 5
- 'D1[+X5 IF X5>L/2-D1]]
- 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))
- If X > 0 And X < (L / 2 - D1) Then
- Kg_get_station_coordinate = BasePoint + D1 + X
- Else
- Kg_get_station_coordinate = CVErr(xlErrNA)
- End If
- End Select
- Case 4
- 'Mid-Span
- Kg_get_station_coordinate = BasePoint + L / 2
- Case 5
- Select Case Kg_get_span_case(W, L, P1, D1, P2, D2)
- Case 1
- 'NA For distributed
- Kg_get_station_coordinate = CVErr(xlErrNA)
- Case 2
- ' [IF a<Span/2]
- 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))
- If (D1 > L / 2) And D1 <> L Then
- If X > 0 Then
- Kg_get_station_coordinate = BasePoint + X
- Else
- Kg_get_station_coordinate = BasePoint + D1
- End If
- Else
- Kg_get_station_coordinate = CVErr(xlErrNA)
- End If
- Case 3
- 'X32
- 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))
- If X > L / 2 And X < D1 Then
- Kg_get_station_coordinate = BasePoint + X
- Else
- Kg_get_station_coordinate = CVErr(xlErrNA)
- End If
- Case 4
- 'X5 [IF P1 & P2 Exist <Span/2]
- 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))
- If D1 = L / 2 And D2 > L / 2 Then
- If (X > 0) Then
- Kg_get_station_coordinate = BasePoint + D1 + X
- Else
- Kg_get_station_coordinate = CVErr(xlErrNA) 'D1 = L/2 [Already calculated]
- End If
- Else
- Kg_get_station_coordinate = CVErr(xlErrNA)
- End If
- Case 5
- 'D1[+X5 IF X5<L/2-D1]]
- 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))
- If X > (L / 2 - D1) Then
- If (X > 0) Then
- Kg_get_station_coordinate = BasePoint + D1 + X
- Else
- Kg_get_station_coordinate = BasePoint + D1
- End If
- Else
- Kg_get_station_coordinate = CVErr(xlErrNA)
- End If
- End Select
- Case 6
- Select Case Kg_get_span_case(W, L, P1, D1, P2, D2)
- Case 1
- Kg_get_station_coordinate = CVErr(xlErrNA)
- Case 2
- Kg_get_station_coordinate = IIf((D1 > L / 2) And D1 <> L, BasePoint + D1, CVErr(xlErrNA))
- Case 3
- Kg_get_station_coordinate = IIf(D1 > L / 2, BasePoint + D1, CVErr(xlErrNA))
- Case 4
- Kg_get_station_coordinate = IIf(D2 > L / 2, BasePoint + D2, CVErr(xlErrNA))
- Case 5
- Kg_get_station_coordinate = IIf(D2 > L / 2, BasePoint + D2, CVErr(xlErrNA))
- End Select
- Case Else
- Kg_get_station_coordinate = "NOT CALCULATED YET"
- End Select
- End Function
- ''Kg_Sort_Loads is a function used to sort two given loads by their distance and return the first & second load after sorting
- ' 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
- ' -------------------function parameters------------------------
- 'SortIndex :: Index of Load|Distance Required
- 'PorA :: Get Force Value or Get force distance
- 'P1|P2 :: Forces Value
- 'A1|A2 :: Forces Distance
- Public Function kg_sort_loads(SortIndex As Integer, PorA As String, P1 As Double, A1 As Double, P2 As Double, A2 As Double)
- ''IF NOTHING IS GIVEN
- If P1 = 0 And P2 = 0 Then
- 'END Function No sort required
- 'Return 0 For all Fields
- kg_sort_loads = 0
- 'END FUNCTION TO STOP IT FROM CONTINUE
- Exit Function
- End If
- '' IF THERE IS ONLY ONE FORCE GIVEN
- If P1 = 0 Or P2 = 0 Then
- 'P1 or P2 = Zero
- If (P2 = 0 And P1 <> 0) Then
- 'Return P1 & A1
- If SortIndex = 1 Then
- If (PorA = "P") Then
- kg_sort_loads = P1
- Else
- kg_sort_loads = A1
- End If
- Else
- 'IF there is only one force => No Need for Force 2
- kg_sort_loads = 0
- End If
- Else
- 'Return P2 & A2
- If SortIndex = 1 Then
- If (PorA = "P") Then
- kg_sort_loads = P2
- Else
- kg_sort_loads = A2
- End If
- Else
- 'IF there is only one force => Use only one force as min
- kg_sort_loads = 0
- End If
- End If
- Exit Function
- End If
- ''IF TWO FORCES ARE GIVEN
- 'FIRST IF USER PUT TWO FORCES WITH SAME DISTANCE -> MAKE THEM ONE
- If P1 <> 0 And P2 <> 0 And A1 = A2 Then
- If SortIndex = 1 Then
- If (PorA = "P") Then
- kg_sort_loads = P1 + P2
- Else
- kg_sort_loads = A1
- End If
- Else
- 'IF there is only one force => No Need for Force 2
- kg_sort_loads = 0
- End If
- Exit Function
- End If
- 'Second ,IF Two Forces given, Compare distances
- If A1 < A2 Then
- If SortIndex = 1 Then
- If (PorA = "P") Then
- kg_sort_loads = P1
- Else
- kg_sort_loads = A1
- End If
- Else
- If (PorA = "P") Then
- kg_sort_loads = P2
- Else
- kg_sort_loads = A2
- End If
- End If
- Else
- If SortIndex = 1 Then
- If (PorA = "P") Then
- kg_sort_loads = P2
- Else
- kg_sort_loads = A2
- End If
- Else
- If (PorA = "P") Then
- kg_sort_loads = P1
- Else
- kg_sort_loads = A1
- End If
- End If
- End If
- End Function
- 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)
- Dim R As Double, E1 As Double, E2 As Double
- If DISTLOAD <> 0 Then
- '1- Elastic Reaction due to DISTLOAD
- R = DISTLOAD * (SPAN * SPAN * SPAN) / 24
- End If
- If Direction = "Right" Then
- 'Right [R2]
- '2- Elastic Reaction due to P1 (IF EXIST)
- If P1 <> 0 Then
- E1 = 0.5 * A1 * ((P1 * A1 * (SPAN - A1)) / SPAN)
- E2 = 0.5 * (SPAN - A1) * ((P1 * A1 * (SPAN - A1)) / SPAN)
- R = R + (((E1 * 2 / 3 * A1) + (E2 * (A1 + (1 / 3 * (SPAN - A1))))) / SPAN)
- End If
- If P2 <> 0 Then
- '3- Elastic Reaction due to P2 (IF EXIST)
- E1 = 0.5 * A2 * ((P2 * A2 * (SPAN - A2)) / SPAN)
- E2 = 0.5 * (SPAN - A2) * ((P2 * A2 * (SPAN - A2)) / SPAN)
- R = R + (((E1 * 2 / 3 * A2) + (E2 * (A2 + (1 / 3 * (SPAN - A2))))) / SPAN)
- End If
- If CantliverMoment <> 0 Then
- ' R1-LEFT = 1/3 * M * L
- ' The Sign is +ve As CantliverMoment value paramter is negative So R1 will be negative
- R = R + (1 / 3 * CantliverMoment * SPAN)
- End If
- Else
- 'Left[R1]
- If P1 <> 0 Then
- E1 = 0.5 * A1 * ((P1 * A1 * (SPAN - A1)) / SPAN)
- E2 = 0.5 * (SPAN - A1) * ((P1 * A1 * (SPAN - A1)) / SPAN)
- R = R + (((E2 * 2 / 3 * (SPAN - A1)) + (E1 * ((SPAN - A1) + (1 / 3 * A1)))) / SPAN)
- End If
- If P2 <> 0 Then
- E1 = 0.5 * A2 * ((P2 * A2 * (SPAN - A2)) / SPAN)
- E2 = 0.5 * (SPAN - A2) * ((P2 * A2 * (SPAN - A2)) / SPAN)
- R = R + (((E2 * 2 / 3 * (SPAN - A2)) + (E1 * ((SPAN - A2) + (1 / 3 * A2)))) / SPAN)
- End If
- If CantliverMoment <> 0 Then
- ' R2-RIGHT = 1/6 * M * L
- ' TODO - IF CANTLIVER IS AT START | NO NEED FOR THIS FOR NOW
- R = R + (1 / 6 * CantliverMoment * SPAN)
- End If
- End If
- kg_Elastic_Reaction = R
- End Function
- Public Function Kg_Ngtv_Moment_Calculator(Spans_Count As String, rtrn As String, range As range, Cantliver_moment As Double)
- Kg_Moment_Calculator = (range.Cells(0))
- ' Select Case Spans_Count
- ' Case "ONE"
- ' Kg_Moment_Calculator = 0
- ' Case "ONE-CNTLVR"
- ' Kg_Moment_Calculator = Cantliver_moment
- ' Case "TWO"
- ' Select Case rtrn
- ' Case "M1"
- ' Kg_Moment_Calculator = (range.Cells(1, 1))
- ' Case "Mc"
- '
- ' End Select
- '
- ' Case Else
- ' ' Kg_Moment_Calculator = "ERROR"
- ' End Select
- End Function
- Public Function Kg_Spans_counter(range As range, Last_span_as_cantliver As String)
- Dim S1, S2, S3, S4, S5 As Double
- S1 = range.Cells(1)
- S2 = range.Cells(2)
- S3 = range.Cells(3)
- S4 = range.Cells(4)
- S5 = range.Cells(5)
- If (Application.WorksheetFunction.Max(S5, S4, S3, S2) = 0) Then
- If (Last_span_as_cantliver = "YES") Then
- Kg_Spans_counter = "CNTLVR"
- Else
- Kg_Spans_counter = "ONE"
- End If
- ElseIf (Application.WorksheetFunction.Max(S5, S4, S3) = 0) Then
- If (Last_span_as_cantliver = "YES") Then
- Kg_Spans_counter = "ONE-CNTLVR"
- Else
- Kg_Spans_counter = "TWO"
- End If
- ElseIf (Application.WorksheetFunction.Max(S5, S4) = 0) Then
- If (Last_span_as_cantliver = "YES") Then
- Kg_Spans_counter = "TWO-CNTLVR"
- Else
- Kg_Spans_counter = "THREE"
- End If
- ElseIf (Application.WorksheetFunction.Max(S5) = 0) Then
- If (Last_span_as_cantliver = "YES") Then
- Kg_Spans_counter = "THREE-CNTLVR"
- Else
- Kg_Spans_counter = "FOUR"
- End If
- Else
- If (Last_span_as_cantliver = "YES") Then
- Kg_Spans_counter = "FOUR-CNTLVR"
- Else
- Kg_Spans_counter = "FIVE"
- End If
- End If
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement