I fully believe this might be impossible and I may need to completely change the approach I took to my database and lists within my app - but here it goes.
I need to take the numbers from a string, sometimes more than one an example being:
Chicken Bake (45g Carbs)
Chicken Soup (25g Carbs)
I then need to be able to divide these using a ratio (Insulin to Carb Ratio) inputted by the user such as 1 (unit of insulin) to 10 (g of carbs) (1:10)
In this case, I would need the result to show 7 Units of Insulin.
I think the issue here is that I opted to include the numbers in the same string as the words in the list. It would be amazing if somebody could tell me how I could extract the numbers from this string or whether I just need to take a different route with the database (less than ideal). The closest subject Iāve found was this:
Here is the lists in question with the numeric data within the strings - as you can see when the items are chosen users can move to a page where in calculation shall be completed - and the results should be displayed in the label where it reads āRecommended Units of Insulinā.
Hi @tatiang, do you think it would be possible for me to use refer to list items on the page rather than having to hand-type them out as in the example above? Iāve tried it out as best I can to do it this way but itās not returning any results, unfortunately.
try debugging. place a label on ācalculate-screenā and insert what you have in āapp selectedListā into that label. make sure that you are staring out correct.
one thing, if you are starting with a list and want to view it as text, be sure to use the list block
The demo I made would best be used as a function that takes a text string as a parameter and returns a number. You could then feed it a list item (string) and it would return a number.
Edit: Iāve updated the project I linked to so that it uses a function now.
Can you say more about how you intend to use the list? Would a user tap on multiple items in the list and then there would be a button to sum the insulin value?
Hi @tatiang, thank you for this! In my code I want the user to be able to view the list on the calculation page and then press ācalculateā, this should then display the results where the label is. The list shown is actually a list formed from selections the user made on the previous page - so the listed items on the calculations are the items that need to be calculated.
Okay, in that case I would add all of the values up as they are selected, using the function I created in the demo.
So it would look something like this:
When list item is clicked
_____set app insulinTotal to app insulinTotal + extractNumberFromText [list item]
That way, each time a list item is clicked, it adds its insulin value to a running total that can be displayed later.
Or, based on what you wrote, you may want to ā once the user has the custom list of items ā just run a loop on the entire custom list to add each value to a running total. In that case, you donāt have to do any calculations each time an item is clickedā¦ you just do one calculation on the entire list when the user clicks the Calculate button.
Hi @tatiang, Iām really sorry - I thought I responded to this!
Unfortunately Iāve had no luck with this, Iām not exactly sure how to do a loop as you mention or what that really is. One entire calculation would be ideal! Would you be able to explain how I would do this? I have tried a direct copy of your above example with elements changed to suit mine and I think Iām struggling to translate it since the item of which the carbs need to be divided by is actually an app variable and the list item is as well.
A loop is a programming structure that repeats one or more instructions multiple times. In Thunkable, the following blocks ā with the exception of the Navigate and Wait blocks ā can be used to create loops:
@jared Wait, seriously?! I love that you were sitting in a McDonaldās working on a list with McDonaldās menu items for someone else who needed help.
Sit-rep, itās looking like itās going to work!!! I was unsure where those variables had come from - I didnāt realise they were made by the function - thatās definitely something I should learn more about! It was hard enough trying to copy this, Iām so grateful for your help and skills! Iām just trying to iron out a few things on my end with it at the moment but itās looking pretty much sorted!
Hey!! After playing around with it a little bit Iāve got it working for my version, I will go ahead and mark your one as the Solution as I the changes made to the one below are probably less helpful as itās using items from a database list as well as the number to divide by from a variable - thank you so much!
I will definitely try to return the favour! First I will spend some time looking through the code and trying to teach myself what each part means and why it has worked in the first place! Iāve never heard of those, but React Native definitely looks interesting!