The only way I know is like above. Is there a default way where Thunkable tells the index count? I mean like in C++:
for (int i = 0; i < 10; i++) {
// Here I can break in the mid and the index would be value of i
}
Yes, the count with i from _ to _ block is exactly for this purpose.
After you add that block to your project, i will be a variable you can drag into your project from the Variables drawer. It will contain the index (count) of the loop.
Thanks you Tatiang but I have a question. This app is just to demo my usage. This app works fine and when it breaks out I get the index value as 3 in OutputTxt which is right. My request is how do I fit in the βcount with i β¦β block into my program? If I can, then I will get rid of the Index variable and the manual way I am keeping track of the index. Please note I do need the βfor each item β¦β block and the if (j = &) block.
- Shouldnβt OutputTxtβs Text be 4, not 3, since β&β is the fourth element in the list?
If your lists only contain one β&β symbol, thereβs a much easier way to do all of this that doesnβt require loopsβ¦ using the βfirst occurence ofβ list block (see this: Lists - Thunkable Docs):
If your list may contain more than one β&β symbol then youβll need to use a loop. Just replace the βfor each item jβ with a count from 1 to length of app variable InputList and then check to see if the list item at #i = β&β. If so, set OutputTxtβs Text to i.
Iβm using i as the loop variable but you may end up using a different letter; it doesnβt matter as long as itβs consistent within your blocks.
Hi Tatiang,
That is brilliant solution, I tried it but could not make it work. Then Googled and Googled and came up with solution but it is wrong. The issue is it is doing 1-10 times 10 = 100. That is the reason my outputs are corrupted. The #i did not work. I spent couple of hours and finally seeking your help again. I have made it more realistic to my goal. Please advice
ananda
https://x.thunkable.com/copy/1e698113fdf4890cf62d263c5d8642a9
your for-item loop is INSIDE your count-with-i loop so for i=1, you use the for-loop and visit all 10 elements in InputList - for i=2, you do the same thing - so you would have travelled the one list 10 times.
just stick with the count-with-i loop and you will always get the correct index at anytime (it will be at the i-th position - and when you want to know what item you got atht eh i-th position, just use this block
can you describe what you are trying to do? are you using some kind of table look up such that β%β always returns 234 and β@β always return 86, etc? - are those symbols annunciators of some kind? like after β%β you get latitude and longitude?
you can probably use objects in a clearer way to do something like that.
Thanks a lot ManyOne. I did some work still could not figure it out.
https://x.thunkable.com/copy/4963111703c2c3bd8912f85fd01ef4b6
Very sleepy will work on this in the morning. The output I want to see is this:
FoundTxt: Found % at index 1 Found & at index 4 Found @ at index 6 Found 56 at index 8
OutputTxt:45 234 467567 467567 56 89
Please advice, thanks
is your input always like this? (are the symbols always in the same order? I)
β40β, β%β, β50β, β60β, β&β ,β70β, β@β, β80β, β$β, β90β
can it be like this? (can there be 0 or n number before each symbol?)
β40β,β50β, β%β, β66β, β&β ,β77β,β88β,β99β, β@β, β111β, β$β, β129β,β200β
or like this? (can the symbols be in any order - is it ok t have zero numbers between symbols"?
β33"β$β,β&β,β44β,β55β,β@β,β%"
is the string you are analyzing generated by machine?
Please see this modification to your project (the first link you shared) and let me know if thatβs what you had in mind:
https://x.thunkable.com/copy/bd5b5e963aeef877bc520728b8b6b8e0
Why are you wanting the β%β to be found at index 1? Do you realize that Thunkable lists start at index 1 and that the β%β is actually in item #2 of your list? Many programming environments start with list index 0 so that may be part of the confusion here.
Wow thanks Tatiang you made my day!! . ManyOne thanks to you also helping me with the right block to use. Now Good morning to you both, let me clarify both of your queries from earlier replies and the current ones. I am from IBM punch card era Later on C++ and System programming(At Processor-OS interaction level) world. All my 40 + years of programming life starting index is 0 or you can say bit 0. So the slight confusion between us. I tend to think all programming issues in C++ way hence get caught in my own web. You people think in thunkable way a very abstracted way that is just brilliant. The data, demarkers and their positions are all fictitious created just to illustrate my problem. They are totally random. Thanks once again for both of you. I will get back to implementing it in my real program!!
Hi Manyone,
Thanks for the good tip and it got me almost to the solution then I had to sleep, I have answered your questions in the reply to Taitiang. As I said this is just some random data to illustrate my issues.
regards
ananda
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.