# Help needed with retrieving sub-lists

**URL:** <https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062>\
**Category:** Questions about Thunkable X\
**Tags:** beginner, variables, lists, question, help\
**Created:** [September 23, 2021, 2:48am UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062 "2021-09-23T02:48:58Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [September 23, 2021, 2:48am UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/1 "2021-09-23T02:48:58Z")

</div>

@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.

 ![Screen Shot 2564-09-23 at 09.47.29](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/9/5/959f5fa854954a01f18fd52cd26d1536763592c4.png)

 ![Screen Shot 2564-09-23 at 09.48.11](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/4/34dc2f5fb362f05baf21466a90db583d3cb57761.png)

Thank in advance!

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [September 23, 2021, 10:34am UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/2 "2021-09-23T10:34:52Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/d/6/d6a841ef1c93e9fc4529f78cd650b64a0be6ea2a.png)

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [September 23, 2021, 12:20pm UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/3 "2021-09-23T12:20:42Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [September 23, 2021, 1:34pm UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/4 "2021-09-23T13:34:58Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/0/b038454cf1cecc7911691c5c49e3d637100c9986.png)

These are the buttons to show selected timetable  
 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/5/7/577e8a563904fb0a5214f13003734caa024b202b.png)

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [September 24, 2021, 3:32am UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/5 "2021-09-24T03:32:41Z")

</div>

@muneer

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

 ![Screen Shot 2564-09-24 at 10.32.22](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/1/8106691f22eb51c083bba5976c4f54181e4b5590.png)

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [September 24, 2021, 4:04am UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/6 "2021-09-24T04:04:37Z")

</div>

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](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/4) to see that the function does not contain the variable of `today`. It should be in the buttons and in the screen opens events.

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [September 28, 2021, 3:22am UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/7 "2021-09-28T03:22:32Z")

</div>

@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

 ![Screen Shot 2564-09-28 at 10.22.06](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/d/fd2da2f6bb7afc00d02a49195794c388e82200b7.png)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [September 28, 2021, 3:36am UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/8 "2021-09-28T03:36:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [September 28, 2021, 3:38am UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/9 "2021-09-28T03:38:27Z")

</div>

@tatiang  
Here are the ranges for each day:

> [@muneer](#):
>
> - 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

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [September 28, 2021, 3:42am UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/10 "2021-09-28T03:42:16Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [September 28, 2021, 4:00am UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/11 "2021-09-28T04:00:21Z")

</div>

@tatiang

Yes, the range variables change through this code:  
 ![Screen Shot 2564-09-28 at 10.59.23](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/0/b044f13e119aaf3ccc2ed9164425a287cff4169f.png)

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

[https://x.thunkable.com/copy/eb9b73002e6055fd88c1438120aea872](https://x.thunkable.com/copy/eb9b73002e6055fd88c1438120aea872)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [September 28, 2021, 4:51am UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/12 "2021-09-28T04:51:36Z")

</div>

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:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/f/ffd146fdb2e56402603d8e5d1bc9fbb7216a9e29.png)

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [September 28, 2021, 10:23am UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/13 "2021-09-28T10:23:44Z")

</div>

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](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/f/f/ff8084b5efe84e3c1c509076515059b42bbb2e55.png)

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [September 29, 2021, 7:30am UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/14 "2021-09-29T07:30:55Z")

</div>

@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.

 ![Screen Shot 2564-09-29 at 14.30.31](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/c/9/c934d3f24b72716804dbf2683aa897bcfbd8e9f3.png)

[https://x.thunkable.com/copy/771bf829df19a358d2b050a51ac6d1bd](https://x.thunkable.com/copy/771bf829df19a358d2b050a51ac6d1bd)

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [September 29, 2021, 7:47am UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/15 "2021-09-29T07:47:13Z")

</div>

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**.

---

<div class="post-metadata">

**Author:** ![jakeheron](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/jakeheron/32/116818_2.png) [@jakeheron](https://community.thunkable.com/u/jakeheron)\
**Post date:** [September 29, 2021, 7:52am UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/16 "2021-09-29T07:52:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 1:15pm UTC](https://community.thunkable.com/t/help-needed-with-retrieving-sub-lists/1521062/17 "2024-11-08T13:15:06Z")

</div>


