# Istruzioni non eseguite nella action del timer

**URL:** <https://forum.xojo.com/t/istruzioni-non-eseguite-nella-action-del-timer/76384>\
**Category:** Italiano\
**Created:** [July 3, 2023, 7:33am UTC](https://forum.xojo.com/t/istruzioni-non-eseguite-nella-action-del-timer/76384 "2023-07-03T07:33:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ciro\_Marciano](https://forum.xojo.com/user_avatar/forum.xojo.com/ciro_marciano/32/2208_2.png) [@Ciro\_Marciano](https://forum.xojo.com/u/Ciro_Marciano)\
**Post date:** [July 3, 2023, 7:33am UTC](https://forum.xojo.com/t/istruzioni-non-eseguite-nella-action-del-timer/76384/1 "2023-07-03T07:33:08Z")

</div>

ciao, ho una webapp con un timer con all’interno dell’evento Action le istruzioni sotto.

se tolgo il break nella seconda parte (dettaglio avanzamento) le insert non vengono eseguite.  
se lascio il break e faccio subito resume, si.

perchè?

```auto
dim data_end as new date
dim recordid as string
dim durata1,durata2 as double

if data_end.Hour=Gestione_Commesse.orasync.mid(1,2).Val and data_end.Minute=Gestione_Commesse.orasync.mid(4,2).Val then
  
  'dobbiamo recuperare i valori
  Dim db As New MSSQLServerDatabase
  Dim db2 As New MSSQLServerDatabase
  
  db.Host =Gestione_Commesse.host // or just the IP if using the default instance
  db.DatabaseName = Gestione_Commesse.dbnm
  db.UserName = Gestione_Commesse.user // or "Domain\UserID for trusted domain accounts
  db.Password = Gestione_Commesse.pass
  
  If db.Connect Then
    ' ******************************************** AGGIORNAMENTO GG DI RITARDO
    ' recuperiamo l'elenco delle commesse 
    Dim ps As MSSQLServerPreparedStatement
    dim stringa_sql as string
    Dim rs,rs2 As RecordSet 
    
    stringa_sql="Select RecordId,"
    stringa_sql=stringa_sql+"DataSpedizionePrevista,"
    stringa_sql=stringa_sql+"SpedizioneAggiornata,"
    stringa_sql=stringa_sql+"GGRitardo1,"
    stringa_sql=stringa_sql+"GGRitardo2"
    stringa_sql=stringa_sql+" from Gestione_Commesse order by RecordId"
    'break
    rs = db.SQLSelect(stringa_sql)
    if rs <> Nil Then
      ' calcolo giorni di ritardo
      While Not rs.EOF
        recordid=rs.IdxField(1).StringValue
        durata1=0
        durata2=0
        if rs.IdxField(2).StringValue.Trim.Len > 0 then
          dim data_start as new date(rs.IdxField(2).StringValue.mid(7,4).Val,rs.IdxField(2).StringValue.mid(4,2).Val,rs.IdxField(2).StringValue.mid(1,2).Val) 
          durata1=(data_end.TotalSeconds-data_start.TotalSeconds)/86400
          durata1=floor(durata1)
        end if
        ps = db.Prepare("Update Gestione_Commesse set GGRitardo1="+durata1.ToText+" where RecordId='"+recordid+"'")
        rs2 = ps.SQLSelect
        if rs.IdxField(3).StringValue.Trim.Len > 0 then
          dim data_start as new date(rs.IdxField(3).StringValue.mid(7,4).Val,rs.IdxField(3).StringValue.mid(4,2).Val,rs.IdxField(3).StringValue.mid(1,2).Val) 
          durata2=(data_end.TotalSeconds-data_start.TotalSeconds)/86400
          durata2=floor(durata2)
        end if
        ps = db.Prepare("Update Gestione_Commesse set GGRitardo2="+durata2.ToText+" where RecordId='"+recordid+"'")
        rs2 = ps.SQLSelect
        rs.MoveNext
      Wend
      rs.Close
    end if
    
    ' ******************************************** AGGIORNAMENTO AVANZAMENTO PRODUZIONE
    ' recuperiamo l'elenco delle commesse 
    Break
    'MsgBox("Lettura Avanzamento.....")
    
    stringa_sql="Delete from Dettaglio_Avanzamento"
    ps = db.Prepare(stringa_sql)
    rs = ps.SQLSelect
    
    
    db2.Host =Gestione_Commesse.hos2// or just the IP if using the default instance
    db2.DatabaseName = Gestione_Commesse.dbn2
    db2.UserName = Gestione_Commesse.use2 // or "Domain\UserID for trusted domain accounts
    db2.Password = Gestione_Commesse.pas2
    
    If db2.Connect Then
      stringa_sql="select PJT_0 AS COMMESSA,substring(ITMREF_0,1,6) as FAMIGLIA, SUM(EXTQTY_0) AS QTA_PREVISTA,SUM(CPLQTY_0) AS QTA_REALIZZATA,"
      stringa_sql=stringa_sql+" (100*SUM(CPLQTY_0)/SUM(EXTQTY_0)) AS PERCENTUALE from x3.PROD.MFGITM "
      stringa_sql=stringa_sql+"where substring(ITMREF_0,1,6) in('2ASPLL','2SVSSA') "'and PJT_0 ='22731' "
      stringa_sql=stringa_sql+"GROUP BY PJT_0, substring(ITMREF_0,1,6) "
      stringa_sql=stringa_sql+"ORDER BY PJT_0, substring(ITMREF_0,1,6)"
      
      rs = db2.SQLSelect(stringa_sql)
      'break
      if rs <> Nil Then
        ' calcolo AvanzamentoProduzione
        While Not rs.EOF
          ps = db.Prepare("Insert Into Dettaglio_Avanzamento values ('"+rs.IdxField(1).StringValue+"','','"+rs.IdxField(2).StringValue+"',"+rs.IdxField(3).StringValue+","+rs.IdxField(4).StringValue+","+rs.IdxField(5).StringValue+")")
          rs2 = ps.SQLSelect
          'devo aggiornare il dettaglio produzione
          'break
          if rs.IdxField(2).StringValue="2ASPLL" then
            if rs.IdxField(5).IntegerValue=0 then
              ps = db.Prepare("Update Gestione_Commesse set AssSpalle=0 where Commessa='"+rs.IdxField(1).StringValue+"'")
            else
              if rs.IdxField(5).IntegerValue=100 then
                ps = db.Prepare("Update Gestione_Commesse set AssSpalle=1 where Commessa='"+rs.IdxField(1).StringValue+"'")
              else
                ps = db.Prepare("Update Gestione_Commesse set AssSpalle=0.5 where Commessa='"+rs.IdxField(1).StringValue+"'")
              end if
            end if
          end if
          if rs.IdxField(2).StringValue="2SVSSA" then
            if rs.IdxField(5).IntegerValue=0 then
              ps = db.Prepare("Update Gestione_Commesse set Vassoi=0 where Commessa='"+rs.IdxField(1).StringValue+"'")
            else
              if rs.IdxField(5).IntegerValue=100 then
                ps = db.Prepare("Update Gestione_Commesse set Vassoi=1 where Commessa='"+rs.IdxField(1).StringValue+"'")
              else
                ps = db.Prepare("Update Gestione_Commesse set Vassoi=0.5 where Commessa='"+rs.IdxField(1).StringValue+"'")
              end if
            end if
          end if
          rs2 = ps.SQLSelect
          rs.MoveNext
        Wend
        rs.Close
        db2.Close
      end if
    Else
      MsgBox("Connection error:" + db.ErrorMessage)
    End If
    
    db.Close
    
  Else
    MsgBox("Connection error:" + db.ErrorMessage)
  End If
  
end if
```

---

<div class="post-metadata">

**Author:** ![Greg\_O](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o/32/22785_2.png) [@Greg\_O](https://forum.xojo.com/u/Greg_O)\
**Post date:** [July 3, 2023, 11:38am UTC](https://forum.xojo.com/t/istruzioni-non-eseguite-nella-action-del-timer/76384/2 "2023-07-03T11:38:52Z")

</div>

Assicurati che il timer non sia impostato su multiplo, altrimenti si accenderà di nuovo e creerà una condizione di gara

---

<div class="post-metadata">

**Author:** ![Ciro\_Marciano](https://forum.xojo.com/user_avatar/forum.xojo.com/ciro_marciano/32/2208_2.png) [@Ciro\_Marciano](https://forum.xojo.com/u/Ciro_Marciano)\
**Post date:** [July 7, 2023, 8:49am UTC](https://forum.xojo.com/t/istruzioni-non-eseguite-nella-action-del-timer/76384/3 "2023-07-07T08:49:26Z")

</div>

ciao,  
al momento sembra si sia risolto mettendo tra un task e l’altro eseguito nell’evento action

App.SleepCurrentThread(2000)

---

<div class="post-metadata">

**Author:** ![jury\_buono1](https://forum.xojo.com/user_avatar/forum.xojo.com/jury_buono1/32/17255_2.png) [@jury\_buono1](https://forum.xojo.com/u/jury_buono1)\
**Post date:** [July 7, 2023, 12:18pm UTC](https://forum.xojo.com/t/istruzioni-non-eseguite-nella-action-del-timer/76384/4 "2023-07-07T12:18:50Z")

</div>

Non hai messo nessun controllo degli errori, potresti incappare in qualche errore o timeout del db che non intercetti

Mettici un try catch

Oltre a controllare quel che ha già detto Greg
