Hi there ,
I'm trying to print the numbers from 1 to 10 to the screen, but to do that I need a list of integers of length 10 to use with a FOR-EACH loop. However, I don't know how to initialize a list of length 10.
Thanks.
foreach is impossible in this case
Thinking about the if condition to do the loop
By this approach, u can change easily change the tmpMax to any number that u wanna end the list
Hi @Hai Nguyen Ngoc
In OutSystems, there is no built-in initialization for a list.If you want to work with a list, you can do it in the following ways:
In your Screen, create a Local Variable named Numbers with type List of Integer.
In the Screen’s OnInitialize action, create a Local Variable named TmpNumbers with type List of Integer.
Still in OnInitialize, add 10 “ListAppend” steps to fill TmpNumbers with the values 1, 2, 3, …, 10.
After that, call ListAppendAll to copy them into your main list:
Destination: Numbers
Source: TmpNumbers
Now you can use a For Each bound to Numbers to display/print the values.
Hope this helps,
Peter Nguyen.
no need at all for that Tmp list
Hi Hieu,
I understand your point, but if i want to print the numbers from 1 to 100 to the screen? If I do it your way, it's not very feasible.
Thank you for your answer.
honestly, @Hai Nguyen Ngoc ,
OutSystems is a platform designed for business software, making a list of x numbers and print them to the screen is not likely to come up in a real application. It sounds like an exercise for beginners to get to know the different widgets and nodes available.
And your question was about 10.
I disagree. I have a screen with pagination and would like to add a droplist to allow the user to set the number of items to show per page. How do I populate that droplist without the ability to initialize a list of numbers?
That would probably be a few discrete options (10, 20 or 50) ?
it depends on where the possible values come from. If you are happy for it to be hardcoded, a simple ListAppendAll will do. Or you could have the options as a comma separated text in a site property, and do a StringSplit into a list.
I had planned to hard code the list, yes. I am currently trying to add each item separately, because I can't figure out how to initialize a list in ODC. Unfortunately, the droplist widget only contains the first item added (10), followed by 5 0s.
That Options Text is set to zero ( not sure why the 10 shows). So for starters, set both Options text and Options value to the value.
Step 1 : Create three local variables namely
1. NumberList of type Integer List
2. i of Integer default value = 0
3. Length of Integer default value to 10(for example).
Step 2: In OnInitialize
Step3 : on the screen call the list.
Final outcome :