0

Coding a popup dialog in a for loop if error

I've been reading that loops cannot be coded to exit. But I'm trying to figure out if there could be a way by adding an if statement somewhere in the code.

For example, I have a code where I export records from one table to another. In the given case my code doesn't execute the loop (not because of an error, but no records met the criteria), I'd like to get a dialog window saying there are no records to export. But if the loop indeed executes, another dialog that confirms success.

This is my coding:

for i in select Bancos where ID_Record = null do
    record(Bancos,i).(ID_Record := format(number(i), "000"))
end;
for loop1 in select Bancos where 'Exportar Asiento' do
    let rbanco := loop1;
    let repes := cnt((select Asientos)[ID_Record = rbanco.ID_Record and Movimiento = rbanco.Concepto and
                    number(Importe) = number(rbanco.Importe) and
                'Fecha Asiento' = rbanco.'F. Operativa']);
    let repcontab := cnt((select 'Asientos Contabilizados')[Movimiento = rbanco.Concepto and number(Importe) = number(rbanco.Importe) and
                    'Fecha Asiento' = rbanco.'F. Operativa' and
                ID_Record = rbanco.ID_Record]);
    if repes = 0 and repcontab = 0 then
        let nregistro := (create Asientos);
        nregistro.(
            'Fecha Asiento' := rbanco.'F. Operativa';
            ID_Record := rbanco.ID_Record;
            Movimiento := rbanco.Concepto;
            Importe := rbanco.Importe;
            if rbanco.Importe > 0 then
                nregistro.('Cuenta de Cargo' := first((select Cuentas)['ID Cuenta' = "A100-2"]))
            else
                nregistro.('Cuenta de Abono' := first((select Cuentas)['ID Cuenta' = "A100-2"]))
            end
        )
    end
end;
dialog("Exportar Todos / Nuevos", "No hay Registros a Exportar o Existen Duplicados.", ["OK"]);
dialog("Exportar Todos / Nuevos", "Registros Exportados Existosamente.", ["OK"])

Here's the printscreen:

 If I enter the dialog "No hay Registros a Exportar o Existen Duplicados." on line 24, then the window pops up for every record in the table, meaning I have to force exit from the app or click OK for over a 1000 times.

I know that both dialogs are misplaced right know in the code and they pop up every time I run it, but I just wanted to leave them there until I get a solution.

What I've thought about: set a condition at the begining of the coding that also runs through all records and if there are no records to export, the dialog pops up. Else, it can run the loop and end with the final success dialog.

Does this make sense? Any thoughts?

Thanks!

3 replies

null
    • Fred
    • 1 yr ago
    • Reported - view

    You need to figure out a way to check for No hay Registros a Exportar o Existen Duplicados before you start the loop. So your if statement would be:

    if [check for Records or duplicates is true] then alert() else code end

      • Marisol_Echaide
      • 1 yr ago
      • Reported - view

      Thanks Fred. Will work on that!

    • John_Halls
    • 1 yr ago
    • Reported - view
     said:
    I've been reading that loops cannot be coded to exit

     Hi Marisol. I feel a duty to say that loops can be coded to exit in Ninox, just not so easily in the form you are using eg for i in select . There are other formats available of the for statement, and there is also the while statement which can easily be coded to exit.

    Regards John

Content aside

  • Status Answered
  • 1 yr agoLast active
  • 3Replies
  • 94Views
  • 3 Following