All pastes #333630 Raw Edit

Nox23

public text v1 · immutable
#333630 ·published 2007-01-31 00:48 UTC
rendered paste body
Private Function Valider_NAS() As Boolean
        'On enlève les "-" du numéro (eX:111-111-111 = 111111111)
        Dim NASStr() As String = MSK_Emp_NAS.CtlText.Split("-")
        Dim str As String
        Dim NasChar() As Char
        Dim Nas(8) As Integer
        'On réuni tout les index du tableau NASStr dans une seule variable
        str = String.Concat(NASStr)
        'Que l'on renvoye dans un tableau de caractères
        NasChar = str.ToCharArray()
        'On s'assure que la premiere entrée correspond a 1 2 4 5 6 7 ou 9
        If CInt(CStr(NasChar(0))) = 3 Or CInt(CStr(NasChar(0))) = 8 Then Return False
        Dim i As Integer
        For i = 0 To NasChar.GetLength(0) - 1
            Nas(i) = CInt(CStr(NasChar(i)))
        Next

        Dim ind As Integer = 1
        'On effectue la validation des nombres 
        For ind = 1 To 7 Step 2
            Nas(ind) *= 2
            If Nas(ind) >= 10 Then
                Nas(ind) = Nas(ind) - 10 + 1
            End If
        Next

        Dim total = 0
        For i = 0 To Nas.GetLength(0) - 2
            total += Nas(i)
        Next
        'On compare le numéro de validation (Dernière position)
        If (Nas(Nas.GetLength(0) - 1) = 10 - total Mod 10) = 0 Then Return False Else Return True


    End Function