Class Script
    Sub Main
        Dim idEstr As Integer ,Ruota As Integer
        Dim Inizio As Integer,Fine As Integer
        Dim nClasseFrz As Integer
        Dim id As Integer ,k As Integer
        Dim nElemFrz As Integer
        Dim nQAmbetti As Integer
        Dim nEstrTot As Integer
        Dim nFrqMedia As Double
        Dim sNomeFrz As String
        Dim aNumInGioco() As Integer 
        Dim aValStat(,) As Decimal 
        Dim sDirFormazioni = "C:\Users\luigi\Desktop\LottoEdoardo\InstallazioneUtente_v_1_0_24\Formazioni Tradizionali\"
        
        Inizio = 5000
        Fine = EstrazioniArchivio
        Ruota = ScegliRuota
        nEstrTot =(Fine + 1) - Inizio
        Dim aElemFormazione(,) As Integer 
        ReDim aElemFormazione(0,0)
        Call RichiediFormazione(sDirFormazioni , aElemFormazione ,nClasseFrz,sNomeFrz)
        nElemFrz = aElemFormazione.getupperbound(0)
        ReDim aValStat(nElemFrz,4)
        ' indice 0 il ritardo
        '        1 freq
        '        2 ritmax
        '        3 incr rit max
        '        4 presenze
        If Ruota > 0 And nClasseFrz > 1 Then
            For id = 1 To nElemFrz
                ReDim aNumInGioco(0)
                Call GetNumInGiocoFromElemFrz(id ,aElemFormazione,aNumInGioco,nClasseFrz)
                For idEstr = Inizio To Fine
                    ' inserire qui il codice che analizza l'estrazione corrente
                    nQAmbetti = VerificaAmbetto(aNumInGioco,Ruota,idEstr,"")
                    If nQAmbetti > 0 Then
                        aValStat(id,0) = 0
                        aValStat(id,1) = aValStat(id,1) + nQAmbetti
                        aValStat(id,3) = 0
                        aValStat(id,4) = aValStat(id,4) + 1
                    Else
                        aValStat(id,0) = aValStat(id,0) + 1
                        If aValStat(id,0) > aValStat(id,2) Then
                            aValStat(id,2) = aValStat(id,0)
                            aValStat(id,3) = aValStat(id,3) + 1
                        End If
                    End If
                    If ScriptInterrotto Then Exit For
                Next
                Call AvanzamentoElab(1,nElemFrz,id)
                If ScriptInterrotto Then Exit For
            Next
            Dim aV () As String 
            aV = {""," Formazione ","  Ritardo  ","  Frequenza  ","  RitardoMax  ","  IncrRitMax  ","  Presenze  ","  I.C.  "}
            Dim aColW () As Integer 
            aColW = {0,500,100,100,100,100,100,100 }
            Call InitTabella(aV,,,,,,,aColW)
            For id = 1 To nElemFrz
                ReDim aNumInGioco(0)
                Call GetNumInGiocoFromElemFrz(id,aElemFormazione,aNumInGioco,nClasseFrz)
                aV(1) = StringaNumeri(aNumInGioco) 
                aV(2) = aValStat(id,0)
                aV(3) = aValStat(id,1)
                aV(4) = aValStat(id,2)
                aV(5) = aValStat(id,3)
                aV(6) = aValStat(id,4)
                nFrqMedia = Divisione (nEstrTot,aValStat(id,4))
                aV(7) = math.Round(Divisione(aValStat(id,0),nFrqMedia),3)
                Call AddRigaTabella(aV)
            Next
            Call Scrivi("StatisticaAmbetto")
            Call Scrivi("Analisi su formazione : " & sNomeFrz)
            Call Scrivi("Sulla ruota           : " & NomeRuota(Ruota))
            Call Scrivi("Da                    : " & GetInfoEstrazione(Inizio))
            Call Scrivi("A                     : " & GetInfoEstrazione(Fine))
            Call Scrivi("Totali range          : " & nEstrTot)
            Call Scrivi
            Call CreaTabella(2)
        End If
    End Sub
    Sub GetNumInGiocoFromElemFrz(id As Integer ,aElemFormazione (,) As Integer ,byref aNumInGioco () As Integer ,nClasseFrz As Integer )
        Dim k
        ReDim aNumInGioco(nClasseFrz)
        For k = 1 To nClasseFrz
            aNumInGioco(k) = aElemFormazione(id,k)
        Next
    End Sub
    Sub RichiediFormazione(sDirFormazioni As String , byref aElemFormazione (,) As Integer , byref nClasseFrz As Integer  , byref sNome As String )
     
        
        Dim sFile As String = ScegliFileInDirectory ( sDirFormazioni ,"*.csv" )
        If sFile <> "" Then
            If GetElementiFormazione ( sFile ,aElemFormazione) > 0 Then 
                sNome = GetFileNomeSenzaEst (sFile ) 
                nClasseFrz =0 
                For k As Integer = 1 To 90
                    If aElemFormazione(1,k) Then
                        nClasseFrz + =1
                    Else
                        Exit For 
                    End If 
                    
                Next 
            End If 
        End If 
    End Sub
End Class