Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function ConvertToMonths(lifeLength As String) As Double
- Dim years As Double
- Dim months As Double
- Dim parts() As String
- ' Split the input into parts based on spaces
- parts = Split(lifeLength, " ")
- ' Loop through the parts to find years and months
- For i = 0 To UBound(parts)
- If InStr("rl", Left(parts(i), 1)) > 0 Then
- years = Val(parts(i - 1))
- ' Check for "a půl" (and a half)
- If i < UBound(parts) And UCase(parts(i + 1)) = "A" And UCase(parts(i + 2)) = "PŮL" Then
- years = years + 0.5
- End If
- ElseIf Left(parts(i), 1) = "m" Then
- months = Val(parts(i - 1))
- ' Check for "a půl" (and a half)
- If i < UBound(parts) And UCase(parts(i + 1)) = "A" And UCase(parts(i + 2)) = "PŮL" Then
- months = months + 0.5
- End If
- End If
- Next i
- ' Convert to months and return the result
- ConvertToMonths = years * 12 + months
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement