Action every day during 15 days and stop 10 days

ciginfo

Well-Known Member
Licensed User
Longtime User
Hello,
I would automatically trigger an action each day from a given day for 15 days and then stop for 10 days and again for 15 days and then stop for 10 days, so for 2 or 3 years.
GivenDay is the given day

I don't find the adequate double loop
I have tried like this but it's no good.

Now = DateTime.Now
nbrDays = (now-GivenDay)/DateTime.TicksPerDay

Dim y, i As Int
For i = 1 To 15
For y = 1 To 300

If NbrDays = i +10*y Then
ACTION
Exit
End If
Next
Next

Thank you
 

stevel05

Expert
Licensed User
Longtime User
I would be tempted to use the MOD operator so as you have a 25 day cycle it could be something like:

If nbrDays MOD 25 <= 15 Then Action

You'd have to test it to get the correct values as you can get a zero value, my maths isn't good enough to do it without testing it.

You may end up with:

If nbrDays MOD 24 < 15.

But you get the idea.
 
Last edited:
Upvote 0

vb1992

Well-Known Member
Licensed User
Longtime User
Program Start: ActiveDayFlag = True : RestDayFlag = False : ActiveDays as int : ActiveDays =0: RestDays = ActiveDays


'
'
' It would be wise to store these data variables to a file in case program/app restarts
' then read from the data file on restart of program/app
'

If ActiveDayFlag = true then
ActiveDays = ActiveDays + 1
'Do action here
end if

If RestDayFlag = True then
RestDays = RestDays + 1
'Do action here
end if

If ActiveDays = 16 then
ActiveDays = 0 'reset counter
RestDayFlag = True
ActiveDayFlag = False
End if

If RestDays = 11 then
RestDays = 0 reset counter
RestDayFlag = False
ActiveDayFlag = True
End if
 
Last edited:
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
nbrDays MOD is the most interesting.

If nbrDays MOD 25 <= 15 And nbrDays MOD 25 > 0 Then Action
It works very well

Thank you
 
Upvote 0
Top