Help needed with retrieving sub-lists

@muneer

Hi,

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 in advance!

1 Like

If you can explain about the algorithm then I will try to build a code that satisfy the requirements.

In the other hand, the long list of days of the week can be shortened.

If I understand the algorithm it should be the following:

  • Day 2, range1 = 1, range2 = 11
  • Day 3, range1 = 12, range2 = 22
  • Day 4, range1 = 23, range2 = 33
  • Day 5, range1 = 34, range2 = 44
  • Day 6, range1 = 45, range2 = 55

Using these blocks your condition can be reduced to:

2 Likes

@muneer

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.

1 Like

When I redesigned the blocks, I have one thing in mind. These code blocks will be in a function to be called from 3 different buttons:

  • Today Button: which will make thisDay variable equal to TODAY.
  • Yesterday Button: which will make thisDay variable equal to TODAY - 1.
  • Tommow Button: which will make thisDay variable equal to TODAY + 1.

You will then simply run the function and retrieve the sub-list of the required day.

This is the function

These are the buttons to show selected timetable
image

1 Like

@muneer

I added this code however, it doesn’t seem to be working. I’ve attached a screenshot:

2 Likes

Yes, it should not work this way.

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:

current day -1

current day +1

1 Like

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.

I’m just curious if that’s what you’re expecting.

3 Likes

@tatiang
Here are the ranges for each day:

2 Likes

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.

3 Likes

@tatiang

Yes, the range variables change through this code:
Screen Shot 2564-09-28 at 10.59.23

Here is a link as well if you want to check it out:

https://x.thunkable.com/copy/eb9b73002e6055fd88c1438120aea872

1 Like

Okay, figured it out!

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:

2 Likes

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.

See this example
image

1 Like

@muneer @tatiang

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.

https://x.thunkable.com/copy/771bf829df19a358d2b050a51ac6d1bd

1 Like

Please check your codes.

In the buttons next day and previous day you are changing the variable range1 and range2. You should change the variable today.

I also noticed that you are checking the number range in previous day button with number 7, it should be 1.

1 Like

Thank you! It is working perfectly now, we got there in the end!

1 Like