user2414039
user2414039

Reputation:

How do I write if statements to determine which method to use between 2 of them

I need help with if statements to determine which of the 2 method to use (to run a process) based on specified weekday time. Dates are irrelevant. How do this? I do not need help with the the methods.

The two methods AllDocuments and GetDocsInLast60Minutes will be used based on specified times.

Requirements

Use Method AllDocuments

If the time is 8 AM to 9 AM

If the time is 11 AM - 11:05 AM

If the time is 1 PM - 1:05 PM

If the time is 3 PM - 3:05 PM

If the time is 5 PM - 5:05 PM

Use Method GetDocsInLast60Minutes If the time is 9 AM to 5 PM

I am not sure how to go about the if statements

If (time is 8AM to 9AM) Then
Use GetDocsInLast60Minutes 

If (time is between 11 AM and 11:05 AM ) Then
Use AllDocuments
'etc

Upvotes: 0

Views: 49

Answers (1)

Steve
Steve

Reputation: 216313

I think you want to call the first method (AllDocuments) all the times falling in the slots defined and call the second method for all other times between 8am and 17pm not covered by the previous time slots.

A possible approach is to convert the actual time in a TimeSpan and take the minutes to check against a set predefined constants (you could also change them to be settings loaded by your configuration file or from a database)

Dim ts = New TimeSpan(DateTime.Now.Hour, DateTime.Now.Minute, 0)
ts.TotalMinutes.Dump()

' Constants for your timeslots expressend in minutes
Const am8 As Double = 480     ' 480 = 8h * 60min
Const am9 As Double = 540
Const am11 As Double = 660
Const am11_05 As Double = 665
Const pm13 As Double = 780
Const pm13_05 As Double = 785
Const pm15 As Double = 900
Const pm15_05 As Double = 905
Const pm17 As Double = 1020
Const pm17_05 As Double = 1025

Dim tm = ts.TotalMinutes

If (tm >= am8 AndAlso tm <= am9) OrElse
    (tm >= am11 AndAlso tm <= am11_05) OrElse
    (tm >= pm13 AndAlso tm <= pm13_05) OrElse
    (tm >= pm15 AndAlso tm <= pm15_05) OrElse
    (tm >= pm17 AndAlso tm <= pm17_05) Then
    AllDocuments()
Else if(tm >= am8 AndAlso tm <= pm17) Then
    GetDocsInLast60Minutes() 
Else
    Console.WriteLine("No call")
End If

Upvotes: 1

Related Questions