Advertisement
arxeiss

Paja

Nov 12th, 2023 (edited)
1,563
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function ConvertToMonths(lifeLength As String) As Double
  2.     Dim years As Double
  3.     Dim months As Double
  4.     Dim parts() As String
  5.    
  6.     ' Split the input into parts based on spaces
  7.    parts = Split(lifeLength, " ")
  8.    
  9.     ' Loop through the parts to find years and months
  10.    For i = 0 To UBound(parts)
  11.         If InStr("rl", Left(parts(i), 1)) > 0 Then
  12.             years = Val(parts(i - 1))
  13.             ' Check for "a půl" (and a half)
  14.            If i < UBound(parts) And UCase(parts(i + 1)) = "A" And UCase(parts(i + 2)) = "PŮL" Then
  15.                 years = years + 0.5
  16.             End If
  17.         ElseIf Left(parts(i), 1) = "m" Then
  18.             months = Val(parts(i - 1))
  19.             ' Check for "a půl" (and a half)
  20.            If i < UBound(parts) And UCase(parts(i + 1)) = "A" And UCase(parts(i + 2)) = "PŮL" Then
  21.                 months = months + 0.5
  22.             End If
  23.         End If
  24.     Next i
  25.    
  26.     ' Convert to months and return the result
  27.    ConvertToMonths = years * 12 + months
  28. End Function
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement