I am currently designing a school planner application and I need some help with a schedule component I am working on.
I have successfully created an algorithm which displays sub-list of the user’s lessons for that specific day, however, I want to create a function which allows the user to cycle through the next and previous days. If anyone could suggest a way of doing this, it would be greatly appreciated.
Thank you very much for simplifying the code, it works perfectly.
Essentially, I would like to to design an algorithm such that, the user can press a ‘next’ and ‘previous’ day button to view their schedule for the following or previous days.
I understand that this would involve changing the ranges so that the list displays a different sublist however, the code that I designed doesn’t really work; when the user presses ‘next day’ the list changes to show the Friday sublist but, when you press to view the previous day once you have pressed next day, it goes back two days instead of showing the list for the current day.
I am sorry if this isn’t explained very well, but any suggestions would be really appreciated.
Remove the first block from the function Set app variable today to current day of the week
This block should go into both Timetable opens
and Today click
This change should get it to work.
Check the images in this post to see that the function does not contain the variable of today. It should be in the buttons and in the screen opens events.
@muneer
I’ve added this change and it is somewhat working. However, it does not cycle through the days fully: when you click ‘next day’ it will show the list for the following day but when you press it again, it will not show the list for the following day after that. Same with ‘previous day’. In other words, the code is only able to show lists for:
What values are you expecting range1 and range2 to have when it’s Monday? And then if you click next day, what values would you expect range1 and range2 to have? And if you click it a second time?
Because it looks like your equations are:
range1 = (today - 2) * 10 + (today - 1)
which simplifies to 11 * today - 21
and range 2 = (today - 1 ) * 11
which equals 11 * today - 11
If it’s Monday, the day of the week equals 2. So the sub-list range would be from 1 to 11.
Okay, got it. So have you verified that the range variables do in fact change to those values when you click the next/prev buttons?
If it’s possible for you to share the project link, I can take a look.
If the issue only occurs when you click the buttons quickly in succession, then you might need to assign the stored variable timetable to an app variable and work with the app variable. Stored variables can be a little slow to retrieve data.
You’re telling Thunkable to change the value of app variable today to current day of the week + 1. So when you click it once and the day is 2, it changes to 3. But if you click it again, it’s still going to take 2 and add 1. And if you click it again, it will take 2 and add 1. Over and over, always the same. You need to assign a variable to the day of the week when the screen opens and then use that variable in place of the current day of the week value. Or better yet, just use the change by block instead:
When I designed the code for the buttons I was thinking that users would want to see:
Current day
Previous day
Next day
I did not put the codes to go one further to other days. However, if you are doing this then you need to check that the variable today is not larger that 7 or smaller than 1 to keep date range in practical perspective.
Hi, I have added both of your suggestions to the project however, it doesn’t seem to be working; when next or previous day is clicked, the list viewer shows a blank screen. Below is a screenshot of the code I have so far as well as a link to the project.