Using a loop to make a label show a series of information defined by a variable?

skcud

Member
Hey guys! So I have made a wizard in which the first step is for the user to determine how many entries they wish to make. The last page is a summary showing all the values the user entered which were stored in a list. I am using a label in a scrollview to show these entries.

Basically, I was wondering if there is a way to use a 'for loop' with a label. There is only one label, and the number of results to show is determined by a variable. If the user wants 300 results, I can't write out list.get() 300 times. But if I use:
B4X:
For X = 0 to main.noentries
label1.text = list1.get(x)
It will repeatedly rewrite the value of the label, meaning only the last result will be shown.
Anyone have any ideas? Thanks guys.
 

skcud

Member
Is a list view the only way? A listview would work, but it isn't the look I'm going for. It should be a block of text that is easily readable, not a list the user needs to scroll through.

Mentioning listview reminded me of another question I've had about b4a for a really long time, maybe you could give me a hand. When using a listview, is it possible to target a user selection, thus making a menu? I don't mean by using an index, because in this case the list would be dynamic. I'm looking for a way to tell the app to go to a certain page by pressing an item on the list with a particular name.
 
Upvote 0

NJDude

Expert
Licensed User
Longtime User
It should be a block of text that is easily readable, not a list the user needs to scroll through.

Well, you then can use a WebView and load the block as an HTML (you will have to create it of course)

I'm looking for a way to tell the app to go to a certain page by pressing an item on the list with a particular name.

The page you're referring to, is a webpage?, check the ListView manual or the XMLSax tutorial to see it in action.
 
Upvote 0

skcud

Member
By "page' I actually meant app module. So an app page basically. But considering the layout of my app I think I just thought of a way to simulate that effect anyway.

Well, you then can use a WebView and load the block as an HTML (you will have to create it of course)

I had thought about this, but I don't know enough about it to have come up with any ideas of implementation. I'll do some research on it. Thanks for your help :)
 
Upvote 0

rayzrocket

Member
Licensed User
Longtime User
Having same problem with list.get in a for loop

Hello, I'm having the same problem, when a "list" is attempted to be charted. Only the last value is provided when the ".Get" is used inside a "For loop".
Program description (B4A files attached):
The "list" gets populated with data (sine function) every 'Tick'.
And then the list gets plotted as a chart, using Erel's chart module(great work).

In order to make the plot, a "For loop" is used to get the last few(enough to fill the graph only) data entries on the list.

Only the last value in the list is acquired by the .Get call in the "For loop" that builds up the chart data. I have ran several tests, but can't find the bug.

Attached are all my files.

The goal is to make a realtime scrolling chart example.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Hi,

The problem you had is that you are using Global Variables to hold temporary versions of your data. For the array object, an = assignment will just copy a pointer to the original data, so by the time you've copied it 10+ times, it's all pointing to the last version of the data. You need to create a new version of the array each time you want to use it (by Declaring the array again).

I've added 2 Dim statements to your code and commented out the global versions. It seems to work as it should now.

Steve
 

Attachments

  • myfirstcharting1.zip
    10 KB · Views: 234
Last edited:
Upvote 0

rayzrocket

Member
Licensed User
Longtime User
Thank you Steve!!

Great Steve, thanks for the help. That did it!:sign0060:
Although I am still unsure of why the issue occurred. Obviously I am very ignorant of how the variables are stored in memory per how they are declared or how often they are declared.

My simple mind thinks that if a variable is declared (globally) it can be used and re-used anywhere and however one needs to use it. I need to become a bit wiser. And I am concerned about memory usage, and memory/variable optimization.

Thanks much!!!
 
Upvote 0
Top