Validate within a Do While

0

I'm doing a form which selects random questions from a DB, the number of questions is determined by the administrator, but good. Always at the beginning of the questionnaire (Web Panel - Event Start) random questions are selected by this way.

Event Start
    &a = 1
    Do While
       &preguntaSeleccionada.Add(Random() * &CantidadPreguntas)
       &a = &a + 1
    EndDo
EndEvent

By multiplying the " Random() * &cantidad " this gives me numbers from 1 to the last question I have, but there are moments (very little) that are repeated and the idea is not that.

I would like to know if while that Do While works, there is some way to validate that when you do a " &coleccon.Add(&item) " do not enter if there is already an equal data.

Working with Gx15u8 - Java Web

    
asked by Angel Cayhualla 21.06.2018 в 22:38
source

1 answer

1

You can ask if an item is in the collection by using the function IndexOf , which returns zero if the element is not and nonzero (the position in the collection in base 1) if it could find it.

Your code would then look something like this:

Event Start
    &a = 1
    Do While // falta la condición...
        &next = Random() * &CantidadPreguntas
        if &preguntaSeleccionada.IndexOf(&next) = 0
            &preguntaSeleccionada.Add(&next)
            &a = &a + 1
        endif
    EndDo
EndEvent
    
answered by 22.06.2018 / 14:51
source