- Cesar Monroy
- PowerBuilder
- Thursday, 7 January 2021 09:29 PM UTC
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.
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.