Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Function CalculateParkingFee() As Double
- Dim aircraftType As String
- Dim startDateTime As Date
- Dim endDateTime As Date
- Dim peakMonths As String
- Dim peakTariff As Double
- Dim offPeakTariff As Double
- Dim totalFee As Double
- Dim currentDateTime As Date
- ' Чтение данных из ячеек
- aircraftType = Worksheets("Sheet1").Range("H2").Value
- startDateTime = Worksheets("Sheet1").Range("F2").Value + Worksheets("Sheet1").Range("B2").Value
- endDateTime = Worksheets("Sheet1").Range("G2").Value + Worksheets("Sheet1").Range("C2").Value
- peakMonths = "June,July,September,October"
- ' Получение тарифов из таблицы fee_per_aircrafttype
- peakTariff = Application.WorksheetFunction.VLookup(aircraftType, Worksheets("fee_per_aircrafttype").Range("A2:K3"), 6, False)
- offPeakTariff = Application.WorksheetFunction.VLookup(aircraftType, Worksheets("fee_per_aircrafttype").Range("A2:K3"), 7, False)
- ' Инициализация общей стоимости
- totalFee = 0
- ' Начало цикла проверки каждого часа
- currentDateTime = startDateTime
- Do While currentDateTime < endDateTime
- If InStr(1, peakMonths, Format(currentDateTime, "mmmm"), vbTextCompare) > 0 Then
- ' Это пиковый месяц
- totalFee = totalFee + peakTariff
- Else
- ' Это не-пиковый месяц
- totalFee = totalFee + offPeakTariff
- End If
- ' Прибавляем 1 час
- currentDateTime = DateAdd("h", 1, currentDateTime)
- Loop
- ' Возвращаем общую стоимость парковки
- CalculateParkingFee = totalFee
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement