I'm trying to generate an event calendar that starts on a given day of the week.
Thus I calculate the first day of the year, and the required offset to the selected day. Now I need to generate the dates for such offset starting weeks I know that starting date of the week has to be within the given year, even though it may extend to the next year. My sample code is the following:
integer li_index, li_year
date ld_currentdate
li_year = 2021
ld_currentdate = date(li_year, 1, 1)
// Solution: use the SetRedraw function with the listbox...
lb_weeks.SetRedraw(False)
do while ld_currentdate < date(li_year, 12, 31)
yield()
if daynumber(ld_currentdate) = 5 then
messagebox("Current Date Processed", string(li_index) + ": " +
string(ld_currentdate))
ls_currentdate = string(ld_currentdate)
li_index = lb_weeks.additem(ls_currentdate)
li_index++
end if
ld_currentdate = relativedate(ld_currentdate, 1)
loop
// Solution: and turn it on after the loop...
lb_weeks.SetRedraw(True)
It works as expected, but the thing is that without the messagebox, it goes to the land of the never ending loops. And it seem to recall that whenever I used loop, I confronted the same issue: the loop seems to loop too fast to perform anything else (reason why I inserted such a useless yield() at the beginning). In this case, if it weren't for the messagebox, the list box wouldn't be filled out (assuming, of course, that the loop allowed anything else to occur before crashing).
Any pointers (or solutions) to this looping issue will be greatly appreciated.
About point 1: That was the code I was actually using before. I just need to determine which day is going to be considered the starting of the week, get there, and then just count 7 until the end of the year, right? But when examining the output data, I found that after February, the routine was selecting other day of the week. The code was the same, except for the RelativeDate(var, offset), where offset was 7, instead of 1. Nobody wants to get quircky results, so I went for the bigger hammer and actually made sure that I would inspect every single day of the year for being a Thursday