Advertisement
korenizla

тестовое_казиахмедова

Sep 30th, 2023
1,468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Function CalculateParkingFee() As Double
  2.     Dim aircraftType As String
  3.     Dim startDateTime As Date
  4.     Dim endDateTime As Date
  5.     Dim peakMonths As String
  6.     Dim peakTariff As Double
  7.     Dim offPeakTariff As Double
  8.     Dim totalFee As Double
  9.     Dim currentDateTime As Date
  10.    
  11.     ' Чтение данных из ячеек
  12.    aircraftType = Worksheets("Sheet1").Range("H2").Value
  13.     startDateTime = Worksheets("Sheet1").Range("F2").Value + Worksheets("Sheet1").Range("B2").Value
  14.     endDateTime = Worksheets("Sheet1").Range("G2").Value + Worksheets("Sheet1").Range("C2").Value
  15.     peakMonths = "June,July,September,October"
  16.    
  17.     ' Получение тарифов из таблицы fee_per_aircrafttype
  18.    peakTariff = Application.WorksheetFunction.VLookup(aircraftType, Worksheets("fee_per_aircrafttype").Range("A2:K3"), 6, False)
  19.     offPeakTariff = Application.WorksheetFunction.VLookup(aircraftType, Worksheets("fee_per_aircrafttype").Range("A2:K3"), 7, False)
  20.    
  21.     ' Инициализация общей стоимости
  22.    totalFee = 0
  23.    
  24.     ' Начало цикла проверки каждого часа
  25.    currentDateTime = startDateTime
  26.     Do While currentDateTime < endDateTime
  27.         If InStr(1, peakMonths, Format(currentDateTime, "mmmm"), vbTextCompare) > 0 Then
  28.             ' Это пиковый месяц
  29.            totalFee = totalFee + peakTariff
  30.         Else
  31.             ' Это не-пиковый месяц
  32.            totalFee = totalFee + offPeakTariff
  33.         End If
  34.         ' Прибавляем 1 час
  35.        currentDateTime = DateAdd("h", 1, currentDateTime)
  36.     Loop
  37.    
  38.     ' Возвращаем общую стоимость парковки
  39.    CalculateParkingFee = totalFee
  40. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement