[code] // Day additions (use the RadioButton selection)
If RB_Kind_Daily.Value And Date_Run.DayOfWeek <> 1 Then
// Daily Strips only [No Sunday]
Date_Run.Day = Date_Run.Day + 1
ElseIf RB_Kind_Sunday.Value Then
// Sunday Strips only
Date_Run.Day = Date_Run.Day + 7
ElseIf RB_Kind_All.Value Then
// Daily and Sunday Strips [7 days a week]
Date_Run.Day = Date_Run.Day + 1
Else
// To avoid infinite loop (why Lord, why ?)
Date_Run.Day = Date_Run.Day + 1
End If[/code]
When I add the Else statement, the code runs correctly (Because in the Else I add 1 day and this is OK in that specific case: pure hazard).
RB_Kind are three RadioButtons. In the case above, the RB_Kind_Daily.Value is True.
The code is in a Do / Loop Until dates compares
Nota: there are 3 RadioButtons because there are three Cases: Monday-Saturday, Sundays and Monday -Sunday. That code was working until today. That is why I worked on it today.
Yes, I cleared the Xojo Cache.
Also, I add a log in a Listbox that report the important values: without the Else block, the loop is infinite
Julian already answered, I’m just testing and learning.
So your options are:
a) RB_Kind_All, always add 1 day
b) RB_Kind_Sunday, add 7 days for DayOfWeek = 1
c) RB_Kind_Daily, add 1 day except Sunday when you add 2
You have:
a) if it is Sunday, it could be 7 or 2 days to add (_Sunday or _Daily)
b) any other day you add 1 day
I think this code will work:
// Day additions (use the RadioButton selection)
If Date_Run.DayOfWeek = 1 Then
If RB_Kind_Sunday.Value Then
Date_Run.Day = Date_Run.Day + 7
Elseif RB_Kind_Daily.Value Then
Date_Run.Day = Date_Run.Day + 2
End If
Else
Date_Run.Day = Date_Run.Day + 1
End If
Edit: I think my code is different, you are not adding 2 to RB_Kind_Daily on Sunday. I think you code will add 1 if RB_Kind_Daily is selected and DayOfWeek <> 1, but it also will add 1 if RB_Kind_Daily is selected and DayOfWeek = 1 via Else, making it the same as RB_Kind_All.
Emile, I suggest you restructure the code a bit to help you think more clearly about it.
// Day additions (use the RadioButton selection)
If RB_Kind_Daily.Value Then
If Date_Run.DayOfWeek <> 1 Then
// Daily Strips only [No Sunday]
Date_Run.Day = Date_Run.Day + 1
Else
// It's Sunday, what should I do???
End If
ElseIf RB_Kind_Sunday.Value Then
// Sunday Strips only
Date_Run.Day = Date_Run.Day + 7
ElseIf RB_Kind_All.Value Then
// Daily and Sunday Strips [7 days a week]
Date_Run.Day = Date_Run.Day + 1
Else
// None of the RadioButtons are selected???
End If
As Julian points out, if your loop depends on Date_Run being incremented, then you really only have 2 conditions if you want to avoid an infinite loop:
RB_Kind_Sunday, add 7
Everything else, add 1
Give some thought to how your loop should function, there may be a better way.
No. There are two cases here: the condition includes Sundays OR excludes Sundays (rare but existant).
Julian: I am usure if I really understand what you wrote. I added the Else case (unneeded) just to be sure one day inc is done / the loop exits somewhere Having a value of 60K or more after cmd-. is impossible. In my testings, I often use cases where I know the results before trying in unknow results.
THe real code does not had the Else statement.
Also, I may not be clear, bu the Else in my code was a despair attempt to make the code running (or better: to know why the Day is not incremented )
This is a simple case with three possible solutions, but I have a blockage with it. I will try with Mon-Sat and Sunday only (two tests) to know what happens.
Dave, thank you, I didn’t know you can use an If statement like that. Definitely I learn a lot just by reading the forum.
Emile, maybe you can share a sample project with a little more information and not just the if…then elseif…, I think with that someone can tell you what is happening.
Don’t mind the code below. I wrote this before I completely read your last post: “Sometimes the loop does not exits !”. Just post a sample with the loop and I’m sure someone will help you.
Your original code check:
1.- If RB_Kind_Daily AND DayOfWeek <> 1, Date_Run.Day + 1
I think this will only happen when the radio button is in Daily and DayOfWeek <> 1 (2-7)
2.- if RB_Kind_Sunday, Date_Run.Day + 7
I think this will happen any day just for the radio button set to Sunday, even if DayOfWeek is 2-7
3.- if RB_Kind_All, Date_Run.Day+1
I think this will happen for every DayOfWeek
You had to add the Else to catch RB_Kind_Daily AND DayOfWeek = 1. Without it you will end in a loop that will no add 1 to Date_Run.Day.
Because you added the Else statement, now your If…Then ElseIf statement works just like:
If RB_Kind_Sunday.Value Then
// This executes even if Date_Run.DayOfWeek <> 1
Date_Run.Day = Date_Run.Day + 7
Else
Date_Run.Day = Date_Run.Day + 1
End If
Maybe someone with more experience can check this.
When result = If(expression, resultWhenTrue, resultWhenFalse) was added ?
I searched from 2015r2 (it does not exists in 2015r1) in the New Items parts of the Release Notes and found nothing.
Also, this information does not appears in the LR entry.
So, in what Xojo version result = If(expression, resultWhenTrue, resultWhenFalse) appears ?