Je ne sais pas trop, mais le but et d'exploiter les données.
Toujours concernant AI 8006
Format: N4+N14+N2+N2
Pattern GS1: ^8006(\d{14})(\d{2})(\d{2})$
La vérification de la clé de contrôle sur N14 "CheckSum"
Sur le 1er N2 = N° de la pièce (2 chiffres)
Sur le 2éme N2 = Nombre total de pièces (2 chiffres)
Pour les pièces Sur GS1 ils parlement de "pieceoftotal"
https://gs1.github.io/gs1-syntax-dictionary/lint__pieceoftotal_8c.html
Et ce Code:
{ /// \cond #define P(i) data[i] #define T(i) data[len / 2 + i] /// \endcond size_t pos, len, i; int pieceiszero, totaliszero, compare; assert(data); len = strlen(data); /* * Data must be a non-zero, even number of characters. * */ if (len == 0 || len % 2 != 0) { if (err_pos) *err_pos = 0; if (err_len) *err_len = len; return GS1_LINTER_INVALID_LENGTH_FOR_PIECE_OF_TOTAL; } /* * Data must consist of all digits. * */ if ((pos = strspn(data, "0123456789")) != len) { if (err_pos) *err_pos = pos; if (err_len) *err_len = 1; return GS1_LINTER_NON_DIGIT_CHARACTER; } /* * Determine whether either the piece number or total piece count is * zero and whether the piece number exceeds the total piece count. * */ pieceiszero = totaliszero = 1; compare = 0; /* -1:P<T ; 0:P==T ; 1:P>T */ for (i = 0; i < len / 2; i++) { if (pieceiszero && P(i) != '0') pieceiszero = 0; if (totaliszero && T(i) != '0') totaliszero = 0; if (!compare && P(i) != T(i)) compare = P(i) < T(i) ? -1 : 1; } /* * Neither piece nor total may be zero. * */ if (pieceiszero || totaliszero) { if (err_pos) *err_pos = pieceiszero ? 0 : len / 2; if (err_len) *err_len = len / 2; return pieceiszero ? GS1_LINTER_ZERO_PIECE_NUMBER : GS1_LINTER_ZERO_TOTAL_PIECES; } /* * The piece number must not exceed the total piece count. * */ if (compare == 1) { if (err_pos) *err_pos = 0; if (err_len) *err_len = len; return GS1_LINTER_PIECE_NUMBER_EXCEEDS_TOTAL; } return GS1_LINTER_OK; }
Je ne sais pas trop, mais le but et d'exploiter les données.
Quand tu sauras ce que tu veux en faire, on réfléchira aux façons d'y parvenir.
Le code C que tu donnes, vérifie que le numéro de la pièce n'est pas supérieur au nombre total de pièces et que ces 2 valeurs ne valent pas 0.
L'objectif de la récupération des data de plus d'un groupe est d'exploiter les informations contenue dans un code-barres et de vérifier l'exactitude de ces données.
Nous avons pu vérifier par exemple l'AI 01 et ça clé de contrôle:
Il est possible de récupérer sur cet AI 01 le préfix de compagnie.
En utilisant ce code-barres:
codes = Array ("]d20100884838083332" + Chr(29) + "21DE77659162" + Chr(29) + "240866471" + Chr(29) + "422276" + Chr(29) + "17230419")
Le code:
https://gs1.github.io/gs1-syntax-dictionary/lint__key_8c.html
Permet de générer une url:
https://id.gs1.org/01/00884838083332/21/DE77659162?240=866471&422=276
Cette URL nous dit que la compagnie est (Philips Healthcare).
----------------------------------------
Ensuite nous avons l'AI 422 l'origine.
Elle doit nous permettre de récupérer le nom du pays.
Les codes iso3166, iso3166999, iso3166alpha2 et iso3166list
https://gs1.github.io/gs1-syntax-dictionary/
Ou depuis un CSV:
https://github.com/lukes/ISO-3166-Countries-with-Regional-Codes/blob/master/all/all.csv
La valeur 276 de l'IA 422 de notre code-barres donne: GERMANY
----------------------------------------
Ensuite nous avons l'AI 17 la date d'expiration.
Le code:
https://gs1.github.io/gs1-syntax-dictionary/lint__yymmd0_8c.html
Cela doit nous permettre le formatage de la date:
De 230419 vers 23/04/19 est surtout de vérifier qu'elle est valide.
Au final cela pourrait ressemble à ceci:
Dans certain cas, exemple L'AI 8006 c'est informations font partie de groupes de data supplémentaire.
Pour finaliser ma requête, penses-tu qu'une modification de ton code puisse gérer les patterns de plus d'1 groupe de data:
Gestion actuelle:
\(?(8006|8026)\)?(\d{14}\d{2}\d{2})
Gestion future:
\(?(8006|8026)\)?(\d{14})?(\d{2})?(\d{2})
C'est mieux ainsi:
Pour traiter les groupes supplémentaires correctement, il faut déjà savoir quel est l'AI.
Du coup, je continue à penser que le plus simple est de redécouper la chaine dans le select case.
Tu ajoutes un attribut à la classe que tu remplis quand c'est nécessaire.
Si tu veux découper dès la regex, il va falloir de prévoir stocker n informations même si beaucoup n'en ont qu'une.
Et de toute façon, il faudra un autre select case pour savoir ce qu'on en fait.
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionAprès analyse, sur nos 50 groupes de 50 patterns, 39 ont qu'un seul groupe de data.
10 ont 2 groupes de data.
1 seul possède 3 groupes de data et est lié aux AI 8006 et 8026.
Pourrais-tu me faire un exemple de découpage de chaine dans le Select Case?
Par exemple sur:
Select Case AI Case "8006" madescription = "(8006) ITIP: " End Select
Avec la vérification que le numéro de la pièce n'est pas supérieur au nombre total de pièces et que ces 2 valeurs ne valent pas 0.
Ci-dessous les codes avec tous les patterns traités et les Select Case déclarés.
Module:
Function TestNeriXs4(Code As String) As String Dim fnc1, gs, caracteresOK, pattern, ligne1, ligne2 As String Dim regex, Match As Object Dim i As Integer Dim resultats As Collection Dim unCode As unCode Dim boucleOut As Boolean Dim patterns As New Collection Set regex = New RegExp 'écriture des patterns unitaires gs = "(\x1d|GS|\()?" 'quand c'est peut-être fnc1 = "(\x1d|GS|$|\()" 'quand c'est obligé caracteresOK = "[\x21\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]" 'Groupe 1 'Balise: 00 'Pattern GS1: ^0(\d{18})$ patterns.Add "(?:](?:C1|e0|d2|Q3|J1))?\(?(00)\)?(\d{18})" + gs 'Groupe [2] 'Balise: 01, 02 'Pattern GS1: ^X(\d{14})$ patterns.Add "(?:](?:C1|e0|d2|Q3|J1))?\(?(01|02)\)?(\d{14})" + gs 'Groupe [3] 'Balise: 10, 21, 22, 243, 254, 420, 710, 711, 712, 713, 714, 715, 4318, 7020, 7021, 7022, 7240, 8002, 8012 'Pattern GS1: ^X([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,20})$ patterns.Add "\(?(10|2[12]|243|254|520|71[0-5]|4318|702[0-2]|7240|8002|8012)\)?(" + caracteresOK + "{0,20})" + fnc1 'Groupe [4] 'Balise: 20 'Pattern GS1: ^20(\d{2})$ patterns.Add "\(?(20)\)?(\d{2})" + gs 'Groupe [5] 'Balise: 235 'Pattern GS1: ^235([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,28})$ patterns.Add "\(?(235)\)?(" + caracteresOK + "{0,28})" + fnc1 'Groupe [6] 'Balise: 90, 240, 241, 250, 251, 400, 401, 403, 4308, 4319, 7002, 7023, 8004 'Pattern GS1: ^X([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,30})$ patterns.Add "\(?(90|24[0-1]|25[0-1]|40[0-13]|4308|7319|7002|7023|8004)\)?(" + caracteresOK + "{0,30})" + fnc1 'Groupe [7] 'Balise: 242 'Pattern GS1: ^242(\d{0,6})$ patterns.Add "\(?(242)\)?(\d{0,6})" + fnc1 'Groupe [8] 'Balise: 253 'Pattern GS1: ^253(\d{13})([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,17})$ patterns.Add "\(?(253)\)?(\d{13}" + caracteresOK + "{0,17})" + fnc1 'Groupe [9] 'Balise: 255 'Pattern GS1: ^255(\d{13})(\d{0,12})$ patterns.Add "(?:](?:C1|e0|d2|Q3|J1))?\(?(255)\)?(\d{13}\d{0,12})" + fnc1 'Groupe [10] 'Balise: 30, 37 'Pattern GS1: ^X(\d{0,8})$ patterns.Add "\(?(3[07])\)?(\d{0,8})" + fnc1 'Groupe [11] 'Balise: 11, 12, 13, 15, 16, 17 ' 3100 à 3105, 3110 à 3115, 3120 à 3125, 3130 à 3135, 3140 à 3145, 3150 à 3155, 3160 à 3165, ' 3300 à 3305, 3310 à 3315, 3320 à 3325, 3330 à 3335, 3340 à 3345, 3350 à 3355, 3360 à 3365, 3370 à 3375, ' 3500 à 3505, 3510 à 3515, 3520 à 3525, 3530 à 3535, 3540 à 3545, 3550 à 3555, 3560 à 3565, 3570 à 3575, ' 3200 à 3205, 3210 à 3215, 3220 à 3225, 3230 à 3235, 3240 à 3245, 3250 à 3255, 3260 à 3265, 3270 à 3275, 3280 à 3285, 3290 à 3295, ' 3400 à 3405, 3410 à 3415, 3420 à 3425, 3430 à 3435, 3440 à 3445, 3450 à 3455, 3460 à 3465, 3470 à 3475, 3480 à 3485, 3490 à 3495, ' 3600 à 3605, 3610 à 3615, 3620 à 3625, 3630 à 3635, 3640 à 3645, 3650 à 3655, 3660 à 3665, 3670 à 3675, 3680 à 3685, 3690 à 3695, 'Pattern GS1:^11(\d{6})$ patterns.Add "\(?(1[123567]|31[0-6][0-5]|3[35][0-7][0-5]|3[246]\d[0-5])\)?(\d{6})" + gs 'Groupe [12] 'Balise: 7007 'Pattern GS1: ^7007(\d{6,12})$ patterns.Add "\(?(7007)\)?(\d{6,12})" + fnc1 'Groupe [13] 'Balise: 7011 'Pattern GS1: ^7011(\d{6})(\d{0,4})$ patterns.Add "\(?(7011)\)?(\d{6}\d{0,4})" + fnc1 'Groupe [14] 'Balise: 3900 à 3909, 3920 à 3929 'Pattern GS1: ^X(\d{0,15})$ patterns.Add "\(?(390[0-9]|392[0-9])\)?(\d{0,15})" + fnc1 'Groupe [15] 'Balise: 3910 à 3919, 3930 à 3939 'Pattern GS1: ^X(\d{3})(\d{0,15})$ patterns.Add "\(?(391[0-9]|393[0-9])\)?(\d{3}\d{0,15})" + fnc1 'Groupe [16] 'Balise: 3940 à 3943, 8111 'Pattern GS1: ^X(\d{4})$ patterns.Add "\(?(394[0-3]|8111)\)?(\d{4})" + fnc1 'Groupe [17] 'Balise: 3950 à 3959 'Pattern GS1: ^X(\d{0,6})$ patterns.Add "\(?(395[0-9])\)?(\d{0,6})" + fnc1 'Groupe [18] 'Balise: 402 'Pattern GS1: ^402(\d{17})$ patterns.Add "\(?(402)\)?(\d{17})" + fnc1 'Groupe [19] 'Balise: 421 'Pattern GS1:^421(\d{3})([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,9})$ patterns.Add "(?:](?:C1|e0|d2|Q3|J1))?\(?(421)\)?(\d{3}" + caracteresOK + "{0,9})" + fnc1 'Groupe [20] 'Balise: 422, 424, 426 'Pattern GS1: ^X(\d{3})$ patterns.Add "\(?(42[246])\)?(\d{3})" + fnc1 'Groupe [21] 'Balise: 423, 425 'Pattern GS1: ^X(\d{3})(\d{0,12})$ patterns.Add "\(?(423|425)\)?(\d{3}\d{0,12})" + fnc1 'Groupe [22] 'Balise: 427, 7008 'Pattern GS1: ^X([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,3})$ patterns.Add "\(?(427|7008)\)?(" + caracteresOK + "{0,3})" + fnc1 'Groupe [23] 'Balise: 4300, 4301, 4310, 4311, 4320 'Pattern GS1: ^X([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,35})$ patterns.Add "\(?(430[01]|431[01]|4320)\)?(" + caracteresOK + "{0,35})" + fnc1 'Groupe [24] 'Balise: 4302 à 4306, 4312 à 4316, 8110, 8112, 8200 'Pattern GS1: ^X([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,70})$ patterns.Add "\(?(430[23456]|431[23456]|811[02]|8200)\)?(" + caracteresOK + "{0,70})" + fnc1 'Groupe [25] 'Balise: 4307, 4317 'Pattern GS1: ^X([A-Z]{2})$ patterns.Add "\(?(4307|4317)\)?([A-Z]{2})" + fnc1 'Groupe [26] 'Balise: 7230 à 7239 'Pattern GS1: ^X([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{2,30})$ patterns.Add "\(?(723[0-9])\)?(" + caracteresOK + "{2,30})" + fnc1 'Groupe [27] 'Balise: 4309 'Pattern GS1: ^4309(\d{20})$ patterns.Add "\(?(4309)\)?(\d{20})" + fnc1 'Groupe [28] 'Balise: 4321, 4322, 4323 'Pattern GS1: ^X([01])$ patterns.Add "\(?(432[123])\)?([01])" + fnc1 'Groupe [29] 'Balise: 4324, 4325, 7003 'Pattern GS1: ^X(\d{10})$ patterns.Add "\(?(432[45]|7003)\)?(\d{10})" + fnc1 'Groupe [30] 'Balise: 4326, 7006, 8005 'Pattern GS1: ^X(\d{6})$ patterns.Add "\(?(4326|7006|8005)\)?(\d{6})" + fnc1 'Groupe [31] 'Balise: 7001 'Pattern GS1: ^7001(\d{13})$ patterns.Add "\(?(7001)\)?(\d{13})" + fnc1 'Groupe [32] 'Balise: 7004 'Pattern GS1: ^7004(\d{0,4})$ patterns.Add "\(?(7004)\)?(\d{0,4})" + fnc1 'Groupe [33] 'Balise: 410 à 417 'Pattern GS1: ^X(\d{13})$ patterns.Add "\(?(41[0-7])\)?(\d{13})" + gs 'Groupe [34] 'Balise: 7005 'Pattern GS1: ^7005([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,12})$ patterns.Add "\(?(7005)\)?(" + caracteresOK + "{0,12})" + fnc1 'Groupe [35] 'Balise: 8006, 8026 'Pattern GS1: ^X(\d{14})(\d{2})(\d{2})$ patterns.Add "(?:](?:C1|e0|d2|Q3|J1))?\(?(8006|8026)\)?(\d{14}\d{2}\d{2})" + fnc1 'patterns.Add "(?:](?:C1|e0|d2|Q3|J1))?\(?(8006|8026)\)?(\d{14})(\d{2})(\d{2})" + fnc1 'Groupe [36] 'Balise: 8007 'Pattern GS1: ^8007([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,34})$ patterns.Add "\(?(8007)\)?(" + caracteresOK + "{0,34})" + fnc1 'Groupe [37] 'Balise: 8008 'Pattern GS1: ^8008(\d{8})(\d{0,4})$ patterns.Add "\(?(8007)\)?(\d{8}\d{0,4})" + fnc1 'Groupe [38] 'Balise: 8009 'Pattern GS1: ^8009([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,50})$ patterns.Add "\(?(8009)\)?(" + caracteresOK + "{0,50})" + fnc1 'Groupe [39] 'Balise: 8010 'Pattern GS1: ^8010([\x23\x2D\x2F\x30-\x39\x41-\x5A]{5,30})$ patterns.Add "\(?(8010)\)?([\x23\x2D\x2F\x30-\x39\x41-\x5A]{5,30})" + fnc1 'Groupe [40] 'Balise: 7009 'Pattern GS1: ^7009([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,10})$ patterns.Add "\(?(7009)\)?(" + caracteresOK + "{0,10})" + fnc1 'Groupe [41] 'Balise: 7010 'Pattern GS1: ^7010([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,2})$ patterns.Add "\(?(7010)\)?(" + caracteresOK + "{0,2})" + fnc1 'Groupe [42] 'Balise: 7040 'Pattern GS1: ^7040(\d[\x21-\x22\x25-\x2F\x30-\x39\x41-\x5A\x5F\x61-\x7A]{3})$ patterns.Add "\(?(7040)\)?(\d[\x21\x22\x25-\x2F\x30-\x39\x41-\x5A\x5F\x61-\x7A]{3})" + fnc1 'Groupe [43] 'Balise: 8011 'Pattern GS1: ^8011(\d{0,12})$ patterns.Add "\(?(8011)\)?(\d{0,12})" + fnc1 'Groupe [44] 'Balise: 7030 à 7039 'Pattern GS1: ^X(\d{3})([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,27})$ patterns.Add "\(?(703[0-9])\)?(\d{3}" + caracteresOK + "{0,27})" + fnc1 'Groupe [45] 'Balise: 8001 'Pattern GS1: ^8001(\d{14})$ patterns.Add "\(?(8001)\)?(\d{14})" + fnc1 'Groupe [46] 'Balise: 8003 'Pattern GS1: ^8003(\d{14})([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,16})$ patterns.Add "\(?(8003)\)?(\d{14}" + caracteresOK + "{0,16})" + fnc1 'Groupe [47] 'Balise: 8013, 8020 'Pattern GS1: ^X([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,25})$ patterns.Add "(?:](?:C1|e0|d2|Q3|J1))?\(?(8013|8020)\)?(" + caracteresOK + "{0,25})" + fnc1 'Groupe [48] 'Balise: 8017, 8018 'Pattern GS1: ^X(\d{18})$ patterns.Add "\(?(801[78])\)?(\d{18})" + fnc1 'Groupe [50] 'Balise: 91 à 99 'Pattern GS1: ^X([\x21-\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A]{0,90})$ patterns.Add "\(?(9[1-9])\)?(" + caracteresOK + "{0,90})" + fnc1 'valeur par défaut si la regex ne matche pas ligne1 = "Code incorrect" ligne2 = "" Set resultats = New Collection Do boucleOut = False For Each pattern In patterns 'on teste chaque pattern pour le début du code regex.pattern = "^" + pattern If (regex.Test(Code)) Then boucleOut = True ligne1 = "" 'si ça marche, on extrait la partie Set Match = regex.Execute(Code)(0) Set unCode = New unCode unCode.Init Match.SubMatches(0), Match.SubMatches(1) resultats.Add unCode 'on enlève ce qu'on vient de traiter Code = Replace(Code, Match.Value, "") 'et on recommence Exit For End If Next Loop While Len(Code) > 0 And boucleOut 'si boucleOut vaut false c'est qu'on vient de faire un tour complet et qu'on est sur un cas imprévu If boucleOut = False Then ligne1 = "Erreur data imprévue" + vbCrLf End If For i = 1 To resultats.Count Set unCode = resultats(i) ligne1 = ligne1 + unCode.Texte ligne2 = ligne2 + vbCrLf + unCode.Description Next TestNeriXs4 = ligne1 + ligne2 End Function Sub Test() Dim codes() As Variant Dim Code As Variant '# "req=01,02,8006,8026" - Association obligatoire avec l'une des IA énumérées. '# "ex=02,255,37" - association non valable avec l'un des IA énumérés. '# "dlpkey" - Clé primaire de la liaison numérique GS1. '# - "https:///01/../10/../22/..". '# "dlpkey" - Non prit en charge dans ce projet. '# "X" = [\x21\x22\x25-\x2F\x30-\x39\x3A-\x3F\x41-\x5A\x5F\x61-\x7A] ---> GS1 ' [\x21-\x22\x25-\x3F\x41-\x5A\x5F\x61-\x7A] '# "Y" = [\x23\x2D\x2F\x30-\x39\x41-\x5A]] ---> GS1 ---> AI 8010 '# "UIC" = [\x21-\x22\x25-\x2F\x30-\x39\x41-\x5A\x5F\x61-\x7A] ---> GS1 ---> AI 7040 ' [\x21\x22\x25-\x39\x5F\x61-\x7A] 'codes = Array("010084399701370311210601363012345617230601213000105704" + Chr(29) + "3233123456", _ ' "(01)00843997013703(11)210601(3630)123456(17)230601(21)3000105704" + Chr(29) + "(3233)123456", _ ' "(01)00843997013703(02)00843997013703(11)210601(17)230601(21)3000105704", _ ' "010088483808258823543522TTs" + Chr(29) + "21DE7840AL79" + Chr(29) + "91867031", _ ' "010733241412435925330000400220140123456789" + Chr(29) + "210000107668" + Chr(29) + "11210208", _ ' "(01)00843997013703(11)210601(17)230601(10)54gp75P(21)3000105704", _ ' "(01)00843997013703(11)210601(10)54gp75P(17)230601(21)3000105704", _ ' "]C101008838738677920200843997013703112207071723070710220707" + Chr(29) + "21PC22412085", _ ' "010088483808258824254321" + Chr(29) + "21DE7840AL82" + Chr(29) + "90867030" + Chr(29) + "91867030" _ ' ) 'AI:00 - N18, CheckSum clé de contrôle, GCP (GS1 Company Prefix). 'codes = Array("]C100123456789123456789") 'AI:01 - N14, CheckSum clé de contrôle, GCP (GS1 Company Prefix), ex=02,255,37. 'codes = Array("]C10112345678912343") 'AI:02 - N14, CheckSum clé de contrôle, GCP (GS1 Company Prefix), req=37. 'codes = Array("]C10012345678912345678902123456789123433712345") ' 253 'codes = Array("]C1010733241412435925310000400220167TTb3456789" + Chr(29) + "210000107668" + Chr(29) + "11210208", _ ' "]d201073324141243592532800040022011123456789" + Chr(29) + "210000107668" + Chr(29) + "11210208", _ ' "00395011010013000129403123+1021JK+0320+12" + Chr(29) + "4215281500KM" _ ' ) '255, 17, 3902, 90 'codes = Array("2553453120000127" + Chr(29) + "1715030439020500" + Chr(29) + "9001") '8020, 3910, 415 'codes = Array("]C18020AZERTY123456qerty12345678" + Chr(29) + "3910008012345678901234" + Chr(29) + "4151234567891231", _ ' "8020AZERTY123456qerty12345678" + Chr(29) + "3910008012345678901234" + Chr(29) + "4151234567891231", _ ' "41512345678912318020AZERTY123456qerty12345678" + Chr(29) + "3910008012345678901234", _ ' "8020AZERTY123456qerty12345678" + Chr(29) + "41512345678912313910008012345678901234", _ ' "3910008012345678901234" + Chr(29) + "8020AZERTY123456qerty12345678" + Chr(29) + "4151234567891231" _ ' ) 'codes = Array("]d20100884838083332" + Chr(29) + "21DE77659162" + Chr(29) + "240866471" + Chr(29) + "422276") '01, 7007 = AI 01 + 2 Dates, ex 21/05/19 22/04/01 AAMMjj 'codes = Array("01073324141243597007210519220401") '01, 7011 = Ai 01 + date + heure, ex 31/05/19 22:04 'codes = Array("010733241412435970112105192204") '01, 426, 7030 'codes = Array("]C101073324141243594262507030250987654") '00, 403, 421 'codes = Array("00395011010013000129403123+1021JK+0320+12" + Chr(29) + "4215281500KM") 'codes = Array("]C142127640219") '00,8006 codes = Array("]C1003950110153000000118006095011015300270203") '01, 253, 21, 11 'codes = Array("010733241412435925312345678912345" + Chr(29) + "210000107668" + Chr(29) + "11210208") 'codes = Array("]C180068006008439970137030303") 'codes = Array("]C100123456789012345678") 'codes = Array("]C10200843997013703") For Each Code In codes Debug.Print (Code) Debug.Print (TestNeriXs4(CStr(Code))) Debug.Print ("") Next End Sub
Module de classe (unCode)
'Champs utiles Public AI As String Public Code As String 'Initialise l'instance de l'objet UnCode Public Sub Init(LaBalise As String, LeCode As String) AI = LaBalise Code = LeCode End Sub 'Méthode qui retourne un texte sous la forme "(Balise)LeCode" Public Function Texte() As String Texte = "(" & AI & ")" & Code End Function 'Méthode qui retourne un texte sous la forme "(Balise) Description : LeCode" Public Function Description() As String Dim madescription As String Select Case AI Case "00" madescription = "(00) N° CONTENEUR (SSCC): " Case "01" madescription = "(01) N° ARTICLE (GTIN): " Case "02" madescription = "(02) N° ARTICLES CONTENUS: " Case "10" madescription = "(10) N° LOT: " Case "11" madescription = "(11) DATE PRODUCTION: " Case "12" madescription = "(12) DATE ECHEANCE: " Case "13" madescription = "(13) DATE EMBALLAGE: " Case "15" madescription = "(15) DATE PREREMPTION: " Case "16" madescription = "(16) DATE VENTE: " Case "17" madescription = "(17) DATE EXPIRATION: " Case "20" madescription = "(20) VARIANTE ARTICLE: " Case "21" madescription = "(21) N° SÉRIE: " Case "22" madescription = "(22) VARIANTE PRODUIT: " Case "235" madescription = "(235) EXTANSION CONTROLE: " Case "240" madescription = "(240) ID ADDITIONNEL: " Case "241" madescription = "(241) N° PIECE: " Case "242" madescription = "(242) N° VARATION: " Case "243" madescription = "(243) N° EMBALAGE: " Case "250" madescription = "(250) N° SÉRIE SECONDAIRE: " Case "251" madescription = "(251) REF SOURCE: " Case "253" madescription = "(253) IDENTIFICATEUR DOC (GDTI): " Case "254" madescription = "(254) COMPOSANT EXTENSION (GLN): " Case "255" madescription = "(255) N° COUPON (GCN): " Case "30" madescription = "(30) NB VARIABLE ARTICLES: " Case "37" madescription = "(37) COMPTAGE UNITÉ, log: " Case "3100", "3101", "3102", "3103", "3104", "3105" madescription = "(" + AI + ") POIDS NET (kg): " Case "3110", "3111", "3112", "3113", "3114", "3115" madescription = "(" + AI + ") LONGUEUR (m): " Case "3120", "3121", "3122", "3123", "3124", "3125" madescription = "(" + AI + ") LARGEUR (m): " Case "3130", "3131", "3132", "3133", "3134", "3135" madescription = "(" + AI + ") HAUTEUR (m): " Case "3140", "3141", "3142", "3143", "3144", "3145" madescription = "(" + AI + ") SUPERFICIE (m²): " Case "3150", "3151", "3152", "3153", "3154", "3155" madescription = "(" + AI + ") VOLUME NET (l): " Case "3160", "3161", "3162", "3163", "3164", "3165" madescription = "(" + AI + ") VOLUME NET (m³): " Case "3200", "3201", "3202", "3203", "3204", "3205" madescription = "(" + AI + ") POIDS NET (lb): " Case "3210", "3211", "3212", "3213", "3214", "3215" madescription = "(" + AI + ") LONGUEUR (in): " Case "3220", "3221", "3222", "3223", "3224", "3225" madescription = "(" + AI + ") LONGUEUR (ft): " Case "3230", "3231", "3232", "3233", "3234", "3235" madescription = "(" + AI + ") LONGUEUR (yd): " Case "3240", "3241", "3242", "3243", "3244", "3245" madescription = "(" + AI + ") LARGEUR (in): " Case "3250", "3251", "3252", "3253", "3254", "3255" madescription = "(" + AI + ") LARGEUR (ft): " Case "3260", "3261", "3262", "3263", "3264", "3265" madescription = "(" + AI + ") LARGEUR (yd): " Case "3270", "3271", "3272", "3273", "3274", "3275" madescription = "(" + AI + ") HAUTEUR (in): " Case "3280", "3281", "3282", "3283", "3284", "3285" madescription = "(" + AI + ") HAUTEUR (ft): " Case "3290", "3291", "3292", "3293", "3294", "3295" madescription = "(" + AI + ") HAUTEUR (yd): " Case "3300", "3301", "3302", "3303", "3304", "3305" madescription = "(" + AI + ") POIDS BRUT (kg): " Case "3310", "3311", "3312", "3313", "3314", "3315" madescription = "(" + AI + ") LONGUEUR (m), log: " Case "3320", "3321", "3322", "3323", "3324", "3325" madescription = "(" + AI + ") LARGEUR (m), grume: " Case "3330", "3331", "3332", "3333", "3334", "3335" madescription = "(" + AI + ") HAUTEUR (m), grume: " Case "3340", "3341", "3342", "3343", "3344", "3345" madescription = "(" + AI + ") SUPERFICIE (m²), log: " Case "3350", "3351", "3352", "3353", "3354", "3355" madescription = "(" + AI + ") VOLUME (l), log: " Case "3360", "3361", "3362", "3363", "3364", "3365" madescription = "(" + AI + ") VOLUME (m³), log: " Case "3370", "3371", "3372", "3373", "3374", "3375" madescription = "(" + AI + ") KG PAR m²: " Case "3400", "3401", "3402", "3403", "3404", "3405" madescription = "(" + AI + ") POIDS BRUT (lb): " Case "3410", "3411", "3412", "3413", "3414", "3415" madescription = "(" + AI + ") LONGUEUR (po), bille: " Case "3420", "3421", "3422", "3423", "3424", "3425" madescription = "(" + AI + ") LONGUEUR (ft), bille: " Case "3430", "3431", "3432", "3433", "3434", "3435" madescription = "(" + AI + ") LONGUEUR (yd), bille: " Case "3440", "3441", "3442", "3443", "3444", "3445" madescription = "(" + AI + ") LARGEUR (po), grume: " Case "3450", "3451", "3452", "3453", "3454", "3455" madescription = "(" + AI + ") LARGEUR (ft), grume: " Case "3460", "3461", "3462", "3463", "3464", "3465" madescription = "(" + AI + ") LARGEUR (yd), grume: " Case "3470", "3471", "3472", "3473", "3474", "3475" madescription = "(" + AI + ") HAUTEUR (po), grume: " Case "3480", "3481", "3482", "3483", "3484", "3485" madescription = "(" + AI + ") HAUTEUR (ft), grume: " Case "3490", "3491", "3492", "3493", "3494", "3495" madescription = "(" + AI + ") HAUTEUR (yd), grume: " Case "3500", "3501", "3502", "3503", "3504", "3505" madescription = "(" + AI + ") SUPERFICIE (in²): " Case "3510", "3511", "3512", "3513", "3514", "3515" madescription = "(" + AI + ") SURFACE (pi²): " Case "3520", "3521", "3522", "3523", "3524", "3525" madescription = "(" + AI + ") SUPERFICIE (yd²): " Case "3530", "3531", "3532", "3533", "3534", "3535" madescription = "(" + AI + ") SUPERFICIE (in²), log: " Case "3540", "3541", "3542", "3543", "3544", "3545" madescription = "(" + AI + ") SUPERFICIE (pi²), log: " Case "3550", "3551", "3552", "3553", "3554", "3555" madescription = "(" + AI + ") SUPERFICIE (yd²), log: " Case "3560", "3561", "3562", "3563", "3564", "3565" madescription = "(" + AI + ") POIDS NET (t oz): " Case "3570", "3571", "3572", "3573", "3574", "3575" madescription = "(" + AI + ") VOLUME NET (oz): " Case "3600", "3601", "3602", "3603", "3604", "3605" madescription = "(" + AI + ") VOLUME NET (qt): " Case "3610", "3611", "3612", "3613", "3614", "3615" madescription = "(" + AI + ") VOLUME NET (gal.): " Case "3620", "3621", "3622", "3623", "3624", "3625" madescription = "(" + AI + ") VOLUME (qt), log: " Case "3630", "3631", "3632", "3633", "3634", "3635" madescription = "(" + AI + ") VOLUME (gal.), log: " Case "3640", "3641", "3642", "3643", "3644", "3645" madescription = "(" + AI + ") VOLUME (po³): " Case "3650", "3651", "3652", "3653", "3654", "3655" madescription = "(" + AI + ") VOLUME (pi³): " Case "3660", "3661", "3662", "3663", "3664", "3665" madescription = "(" + AI + ") VOLUME (yd³): " Case "3670", "3671", "3672", "3673", "3674", "3675" madescription = "(" + AI + ") VOLUME (po³), bille: " Case "3680", "3681", "3682", "3683", "3684", "3685" madescription = "(" + AI + ") VOLUME (pi³), rondin: " Case "3690", "3691", "3692", "3693", "3694", "3695" madescription = "(" + AI + ") VOLUME (yd³), log: " Case "3900", "3901", "3902", "3903", "3904", "3905", "3906", "3907", "3908", "3909" madescription = "(" + AI + ") MONTANT: " Case "3910", "3911", "3912", "3913", "3914", "3915", "3916", "3917", "3918", "3919" madescription = "(" + AI + ") MONTANT (ISO): " Case "3920", "3921", "3922", "3923", "3924", "3925", "3926", "3927", "3928", "3929" madescription = "(" + AI + ") PRIX: " Case "3930", "3931", "3932", "3933", "3934", "3935", "3936", "3937", "3938", "3939" madescription = "(" + AI + ") PRIX (ISO): " Case "3940", "3941", "3942", "3943" madescription = "(" + AI + ") REMISE %: " Case "3950", "3951", "3952", "3953", "3954", "3955" madescription = "(" + AI + ") PRIX / UoM: " Case "400" madescription = "(400) NUMÉRO DE COMMANDE: " Case "401" madescription = "(401) N° INDENTIFICATION (GINC): " Case "402" madescription = "(402) N° INDENTIFICATION (GSIN): " Case "403" madescription = "(403) CODE ROUTAGE: " Case "410" madescription = "(410) EXPÉDIER À: " Case "411" madescription = "(411) FACTURER À: " Case "412" madescription = "(412) ACHAT AUPRÈS DE: " Case "413" madescription = "(413) EXPÉDIER POUR: " Case "414" madescription = "(414) N° LOC: " Case "415" madescription = "(415) PAYER À: " Case "416" madescription = "(416) PROD/SERV LOC: " Case "417" madescription = "(417) PARTIE: " Case "420" madescription = "(420) EXPÉDIER CODE POSTAL: " Case "421" madescription = "(421) EXPÉDIER CODE POSTAL (ISO): " Case "422" madescription = "(422) ORIGINE: " Case "423" madescription = "(423) PROCESSUS INITIAL: " Case "424" madescription = "(424) PAYS - PROCESSUS: " Case "425" madescription = "(425) PAYS - DÉSASSEMBLAGE: " Case "426" madescription = "(426) PAYS - PROCESSUS COMPLET: " Case "427" madescription = "(427) SUBDIVISION ORIGINE: " Case "4300" madescription = "(4300) ENVOYER À SOCIÉTÉ: " Case "4301" madescription = "(4301) ENVOYER AU NOM: " Case "4302" madescription = "(4302) ENVOYER À ADD1: " Case "4303" madescription = "(4303) ENVOYER À ADD2: " Case "4304" madescription = "(4304) ENVOYER À BANLIEUE: " Case "4305" madescription = "(4305) ENVOYER À LOC: " Case "4306" madescription = "(4306) ENVOYER VERS REG: " Case "4307" madescription = "(4307) ENVOYER AU PAYS: " Case "4308" madescription = "(4308) ENVOYER AU TÉLÉPHONE: " Case "4309" madescription = "(4309) ENVOI VERS GEO: " Case "4310" madescription = "(4310) RETOUR À SOCIÉTÉ: " Case "4311" madescription = "(4311) RETOUR AU NOM: " Case "4312" madescription = "(4312) RETOUR À ADD1: " Case "4313" madescription = "(4313) RETOUR À ADD2: " Case "4314" madescription = "(4314) RETOUR EN BANLIEUE: " Case "4315" madescription = "(4315) RETOUR À LOC: " Case "4316" madescription = "(4316) RETOUR À REG: " Case "4317" madescription = "(4317) RETOUR AU PAYS: " Case "4318" madescription = "(4318) RETOUR CODE POSTAL: " Case "4319" madescription = "(4319) RETOUR AU TÉLÉPHONE: " Case "4320" madescription = "(4320) DESCRIPTION DU SERVICE: " Case "4321" madescription = "(4321) MARCHANDISES DANGEREUSES: " Case "4322" madescription = "(4322) AUTORISATION DE SORTIE: " Case "4323" madescription = "(4323) SIGNATURE REQUIS: " Case "4324" madescription = "(4324) PAS AVANT DATE: " Case "4325" madescription = "(4325) PAS APRES DATE: " Case "4326" madescription = "(4326) DATE DE SORTIE: " Case "7001" madescription = "(7001) N° STOCK OTAN (NSN): " Case "7002" madescription = "(7002) DÉCOUPE DE VIANDE: " Case "7003" madescription = "(7003) DATE DE PÉREMPTION: " Case "7004" madescription = "(7004) PUISSANCE ACTIVE: " Case "7005" madescription = "(7005) ZONE DE CAPTURE: " Case "7006" madescription = "(7006) DATE DE PREMIERE CONGELATION: " Case "7007" madescription = "(7007) DATE DE RÉCOLTE: " Case "7008" madescription = "(7008) ESPÈCES AQUATIQUES: " Case "7009" madescription = "(7009) TYPE D'ENGIN DE PÊCHE: " Case "7010" madescription = "(7010) MÉTHODE DE PRODUCTION: " Case "7011" madescription = "(7011) DATE LIMITE D'ESSAI: " Case "7020" madescription = "(7020) RÉNOVATION LOT: " Case "7021" madescription = "(7021) STATUS FONCTIONNEL: " Case "7022" madescription = "(7022) STATUS RÉVISION: " Case "7023" madescription = "(7023) ID ASSEMBLAGE(GIAI): " Case "7030" madescription = "(7030) PROCESSEUR ISO # 0: " Case "7031" madescription = "(7031) PROCESSEUR ISO # 1: " Case "7032" madescription = "(7032) PROCESSEUR ISO # 2: " Case "7033" madescription = "(7033) PROCESSEUR ISO # 3: " Case "7034" madescription = "(7034) PROCESSEUR ISO # 4: " Case "7035" madescription = "(7035) PROCESSEUR ISO # 5: " Case "7036" madescription = "(7036) PROCESSEUR ISO # 6: " Case "7037" madescription = "(7037) PROCESSEUR ISO # 7: " Case "7038" madescription = "(7038) PROCESSEUR ISO # 8: " Case "7039" madescription = "(7039) PROCESSEUR ISO # 9: " Case "7040" madescription = "(7040) UIC+EXT: " Case "710" madescription = "(710) NHRN PZN: " Case "711" madescription = "(711) NHRN CIP: " Case "712" madescription = "(712) NHRN CN: " Case "713" madescription = "(713) NHRN DRN: " Case "714" madescription = "(714) NHRN AIM: " Case "715" madescription = "(715) NHRN NDC: " Case "7230" madescription = "(7230) CERT # 1: " Case "7231" madescription = "(7231) CERT # 2: " Case "7232" madescription = "(7232) CERT # 3: " Case "7233" madescription = "(7233) CERT # 4: " Case "7234" madescription = "(7234) CERT # 5: " Case "7235" madescription = "(7235) CERT # 6: " Case "7236" madescription = "(7236) CERT # 7: " Case "7237" madescription = "(7237) CERT # 8: " Case "7238" madescription = "(7238) CERT # 9: " Case "7239" madescription = "(7239) CERT # 10: " Case "7240" madescription = "(7240) PROTOCOLE: " Case "7241" madescription = "(7241) TYPE DE SUPPORT AIDC: " Case "7242" madescription = "(7242) VCN: " Case "8001" madescription = "(8001) DIMENSIONS: " Case "8002" madescription = "(8002) CMT No.: " Case "8003" madescription = "(8003) GRAI: " Case "8004" madescription = "(8004) GIAI: " Case "8005" madescription = "(8005) PRIX PAR UNITÉ: " Case "8006" madescription = "(8006) ITIP: " Case "8007" madescription = "(8007) IBAN: " Case "8008" madescription = "(8008) HEURE PRODUCTION: " Case "8009" madescription = "(8009) OPTSEN: " Case "8010" madescription = "(8010) CPID: " Case "8011" madescription = "(8011) CPID SERIE: " Case "8012" madescription = "(8012) VERSION: " Case "8013" madescription = "(8012) GMN: " Case "8017" madescription = "(8017) GSRN - PRESTATAIRE: " Case "8018" madescription = "(8018) GSRN - DESTINATAIRE: " Case "8019" madescription = "(8019) SRIN: " Case "8020" madescription = "(8020) REF No.: " Case "8026" madescription = "(8026) CONTENU ITIP: " Case "8030" madescription = "(8030) DIGSIG: " Case "8110" madescription = "(8110) CODE COUPON: " Case "8111" madescription = "(8111) POINTS: " Case "8112" madescription = "(8112) ID COUPON: " Case "8200" madescription = "(8200) URL DU PRODUIT: " Case "90" madescription = "(90) INTERNE MUTUELLE: " Case "91", "92", "93", "94", "95", "96", "97", "98", "99" madescription = "(" + AI + ") N° INTERNE: " Case Else madescription = "(" + AI + ") Déscription non codée : " End Select Description = madescription + Code End Function
Avec un minimum de modif (et donc dans ce premier jet pas la présentation que tu as donnée précédemment)
La classe
'Champs utiles Public AI As String Public Code As String Public ValidationData As Boolean 'Initialise l'instance de l'objet UnCode Public Sub Init(LaBalise As String, leCode As String) AI = LaBalise Code = leCode End Sub 'Méthode qui retourne un texte sous la forme "(Balise)LeCode" Public Function Texte() As String Texte = "(" & AI & ")" & Code End Function 'Méthode qui retourne un texte sous la forme "(Balise) Description : LeCode" Public Function Description() As String Dim madescription As String Dim leCode As String leCode = Code ValidationData = True Select Case AI Case "01" madescription = "(01) GTIN de l’article: " Case "11" madescription = "(11) Date de production: " Case "17" madescription = "(17) Date d'expiration : " Case "10" madescription = "(10) Numéro de lot: " Case "21" madescription = "(21) Numéro de série: " Case "91" madescription = "(91) InfosInternes: " Case "8006" Dim data As String Dim numero, totalSerie As Integer madescription = "(8006) ITIP: " data = Left(Code, 14) If CheckSum(data) Then leCode = data + ", checksum OK | " Else leCode = "erreur checksum, " + data + " | " ValidationData = False End If numero = CInt(Mid(Code, 15, 2)) totalSerie = CInt(Right(Code, 2)) If numero = 0 Or totalSerie = 0 Or numero > totalSerie Then leCode = leCode + "Erreur de numérotation, " ValidationData = False End If leCode = leCode + "numéro de la pièce dans la série : " + CStr(numero) + ", nombre de pièces dans la série : " + CStr(totalSerie) Case Else madescription = "(" + AI + ") Déscription non codée : " End Select Description = madescription + leCode End Function Function CheckSum(data As String) As Boolean Dim s, key As Integer s = 0 Dim f As Integer Dim valeur As Variant key = CInt(Right(data, 1)) 'la clé c'est le carractère de droite valeur = Left(data, Len(data) - 1) 'la valeur c'est le reste 'facteur de départ en fonction de la longeur de la valeur If Len(valeur) Mod 2 = 0 Then f = 1 Else f = 3 End If For i = 1 To Len(valeur) s = s + CInt(Mid(valeur, i, 1)) * f f = 4 - f Next i 'on vérifie si la clé est bonne If s Mod 10 = 0 Then CheckSum = (key = 0) Else CheckSum = (key = 10 - s Mod 10) End If End Function
Une modif à la fin de TestNeriXs4
'...tout le début idem Dim ValidationData As Boolean ValidationData = True 'par défaut on considère que tout est correct For i = 1 To resultats.Count Set unCode = resultats(i) ligne1 = ligne1 + unCode.Texte ligne2 = ligne2 + vbCrLf + unCode.Description If unCode.ValidationData = False Then 's'il y a au moins une data incorrecte ça sera signalé ValidationData = False End If Next If ValidationData = False Then ligne2 = vbCrLf + vbCrLf + "Attention ça c'est mal passé !" + vbCrLf + ligne2 End If TestNeriXs4 = ligne1 + ligne2 End Function
Le code de test
Sub test() Dim codes() As Variant Dim Code As Variant 'mise de plusieurs codes de test dans un tableau codes = Array("(01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012315678", _ "(01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012345678", _ "(01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012310078", _ "(01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012315600", _ "(01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012317856", _ "(01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012347856") For Each Code In codes Debug.Print (Code) Debug.Print (TestNeriXs4(CStr(Code))) Debug.Print ("") Next End Sub
Et le résultat
(01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012315678 (01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012315678 (01) GTIN de l’article: 00843997013703 (11) Date de production: 210601 (3630) Déscription non codée : 123456 (17) Date d'expiration : 230601 (8006) ITIP: 12345678901231, checksum OK | numéro de la pièce dans la série : 56, nombre de pièces dans la série : 78 (01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012345678 (01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012345678 Attention ça c'est mal passé ! (01) GTIN de l’article: 00843997013703 (11) Date de production: 210601 (3630) Déscription non codée : 123456 (17) Date d'expiration : 230601 (8006) ITIP: erreur checksum, 12345678901234 | numéro de la pièce dans la série : 56, nombre de pièces dans la série : 78 (01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012310078 (01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012310078 Attention ça c'est mal passé ! (01) GTIN de l’article: 00843997013703 (11) Date de production: 210601 (3630) Déscription non codée : 123456 (17) Date d'expiration : 230601 (8006) ITIP: 12345678901231, checksum OK | Erreur de numérotation, numéro de la pièce dans la série : 0, nombre de pièces dans la série : 78 (01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012315600 (01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012315600 Attention ça c'est mal passé ! (01) GTIN de l’article: 00843997013703 (11) Date de production: 210601 (3630) Déscription non codée : 123456 (17) Date d'expiration : 230601 (8006) ITIP: 12345678901231, checksum OK | Erreur de numérotation, numéro de la pièce dans la série : 56, nombre de pièces dans la série : 0 (01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012317856 (01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012317856 Attention ça c'est mal passé ! (01) GTIN de l’article: 00843997013703 (11) Date de production: 210601 (3630) Déscription non codée : 123456 (17) Date d'expiration : 230601 (8006) ITIP: 12345678901231, checksum OK | Erreur de numérotation, numéro de la pièce dans la série : 78, nombre de pièces dans la série : 56 (01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012347856 (01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012347856 Attention ça c'est mal passé ! (01) GTIN de l’article: 00843997013703 (11) Date de production: 210601 (3630) Déscription non codée : 123456 (17) Date d'expiration : 230601 (8006) ITIP: erreur checksum, 12345678901234 | Erreur de numérotation, numéro de la pièce dans la série : 78, nombre de pièces dans la série : 56
Tous simplement parfait !
Tu as bien fait d'insister sur le Select Case !
Merci
Je devrais pouvoir me débrouiller pour la présentation (Si par présentation, tu fais allusion à l'UserForm!).
Je bute sur truc bête, concernant les 2 messages "checksum" et "numero + totalSerie" .
Les faire s'afficher sur 2 MsgBox distincts ?
En reprenant l'AI concernée.
MsgBox1 = (8006), checksum OK.
MsgBox2 = (8006), pièce 2 sur 3.
C'est Bon, j'y suis !
Source:
data = Left(Code, 14) If CheckSum(data) Then leCode = data + ", checksum OK | " Else leCode = "erreur checksum, " + data + " | " ValidationData = False End If numero = CInt(Mid(Code, 15, 2)) totalSerie = CInt(Right(Code, 2)) If numero = 0 Or totalSerie = 0 Or numero > totalSerie Then leCode = leCode + "Erreur de numérotation, " ValidationData = False End If leCode = leCode + "numéro de la pièce dans la série : " + CStr(numero) + ", nombre de pièces dans la série : " + CStr(totalSerie)
Modifications:
data = Left(Code, 14) If CheckSum(data) Then MsgBox "(" + AI + "), checksum OK !" Else MsgBox "(" + AI + "), erreur checksum !" ValidationData = False End If numero = CInt(Mid(Code, 15, 2)) totalSerie = CInt(Right(Code, 2)) If numero = 0 Or totalSerie = 0 Or numero > totalSerie Then MsgBox "(" + AI + "), Erreur de numérotation." ValidationData = False End If MsgBox "(" + AI + "), pièce " + CStr(numero) + " sur " + CStr(totalSerie)
Je cherche à générer depuis mes codes-barres l'URL GS1 Digital Link URI
Exemple
Avec le code-barres:
"]C1010060791513760121200005429 " + Chr(29) + "111906063001 " + Chr(29) + "101356981"
L'URL doit être crée:
https://id.gs1.org/01/00607915137601/10/1356981/21/200005429?11=190606&30=01
Ce qui donne:
Company Name: Applied Medical Resources Corporation
Le sujet est traité ici:
https://github.com/gs1/gs1-digital-link-uri-simple-parser
Ça semble être du C, que je ne sais pas lire!
D'après cette source et dans mon objectif, ceci est-il facilement réalisable en VBA?
heu, joker.
le fonctionnement ne me saute pas aux yeux.
Peut-être une autre approche!
En jouent avec ce générateur:
https://gs1.github.io/2d-barcode-generator/
J'en conclue qu'on pourrait essayer de coder cette logique:
L'url commence toujours par:
https://id.gs1.org
Suivi d'un slash /
Suivi d'un des 16 AI, appelé "Primary key (AI)" suivant:
00, 01, 253, 255, 401, 402, 414, 415, 417, 7240, 8003, 8004, 8006, 8010, 8017, 8018
Suivi d'un slash /
Suivi de la data correspondent.
Suivi d'un slash /
Suivi d'un des 3 AI, appelé "Key qualifiers (AI)" suivant:
22, 10, 21
Suivi d'un slash /
Suivi de la data correspondent.
Il peut y avoir "0 à 3" Key qualifiers (AI) à la suite, ils sont séparés par un slash /
Suivi d'un point d'interrogation ?, qui marque la fin de Key qualifiers (AI)
Le point d'interrogation ? doit être présent même s'il n'y a pas de Key qualifiers (AI)
Suivi d'un des autres AI restants, appelé "Data attributes (AI)".
Suivi de égale =
Suivi de la data correspondent.
Suivi de l'esperluette & s'il y a plusieurs "Data attributes (AI)" à la suite.
Là aussi "Data attributes (AI)" peut être absent de l'url.
L'ordre des Key qualifiers (AI) et des Data attributes (AI) n'a pas d'importance.
La difficulté est de récupérer les AI + data pour les classer en 3 groupes soit:
Primary key (AI), Key qualifiers (AI) et Data attributes (AI) et reconstituer l'url.
Je me demandais si la source de la convention ne devrait pas être le Code HRI (Human Readable Interpretation) plutôt que le code scanné?
Soit pour l'exemple donné plus tôt:
(01)00843997013703(11)210601(3630)123456(17)230601(8006)123456789012315678
Dans le code, la variable "ligne1".
A mon avis, dans la fonction TestNeriXs4, après avoir créé chaque code et stocké dans la collection, tu ajoutes 2 collections, dans lesquelles tu sotckes les primairies key pour l'une et les Data Attribute pour l'autre.
Et à la fin, tu itères ces 2 collections pour créer ton URL.
Attention, il faut gérer les caractères échappés https://www.delftstack.com/fr/howto/html/html-escape/
Bonjour,
La liste des "Primary Key" et des "Key Qalifier" que j'ai donnés datait de 2018
J'ai mis à jour avec les clés de 2023
https://ref.gs1.org/standards/digital-link/uri-syntax/
Pour les 2 collections je pense que ça va:
Sub List_Primary_Key() Dim Primary_Keys As New Collection Primary_Keys.Add "00" Primary_Keys.Add "01" Primary_Keys.Add "253" Primary_Keys.Add "255" Primary_Keys.Add "401" Primary_Keys.Add "402" Primary_Keys.Add "414" Primary_Keys.Add "415" Primary_Keys.Add "417" Primary_Keys.Add "8003" Primary_Keys.Add "8004" Primary_Keys.Add "8006" Primary_Keys.Add "8010" Primary_Keys.Add "8013" Primary_Keys.Add "8017" Primary_Keys.Add "8018" For Each Primary_Key In Primary_Keys If Primary_Key = "01" Then MsgBox Primary_Key & ", est présent dans la liste!" End If Next Primary_Key End Sub
Sub List_Key_Qualifier() Dim Key_Qualifiers As New Collection Key_Qualifiers.Add "10" Key_Qualifiers.Add "21" Key_Qualifiers.Add "22" Key_Qualifiers.Add "235" Key_Qualifiers.Add "254" Key_Qualifiers.Add "7040" Key_Qualifiers.Add "8011" Key_Qualifiers.Add "8019" Key_Qualifiers.Add "8020" For Each Key_Qualifier In Key_Qualifiers If Key_Qualifier = "254" Then MsgBox Key_Qualifier & ", est présent dans la liste!" End If Next Key_Qualifier End Sub
Mais après je galère vraiment, je ne percute pas! Il me faudrait une 3eme Collections avec tous les autres AI ? entre l'itération et la gestion des caractères échappés !!!
J'ai vraiment besoin d'aide
Dans le doute, en plus de la collection Primary_Keys et de la collection Key_Qualifiers, une troisième collection Data_Attributes.
Sub List_Data_Attribute() Dim Data_Attributes As New Collection Data_Attributes.Add "02" Data_Attributes.Add "11" Data_Attributes.Add "12" Data_Attributes.Add "13" Data_Attributes.Add "15" Data_Attributes.Add "16" Data_Attributes.Add "17" Data_Attributes.Add "20" Data_Attributes.Add "240" Data_Attributes.Add "241" Data_Attributes.Add "242" Data_Attributes.Add "243" Data_Attributes.Add "250" Data_Attributes.Add "251" Data_Attributes.Add "30" Data_Attributes.Add "3100" Data_Attributes.Add "3101" Data_Attributes.Add "3102" Data_Attributes.Add "3103" Data_Attributes.Add "3104" Data_Attributes.Add "3105" Data_Attributes.Add "3110" Data_Attributes.Add "3111" Data_Attributes.Add "3112" Data_Attributes.Add "3113" Data_Attributes.Add "3114" Data_Attributes.Add "3115" Data_Attributes.Add "3120" Data_Attributes.Add "3121" Data_Attributes.Add "3122" Data_Attributes.Add "3123" Data_Attributes.Add "3124" Data_Attributes.Add "3125" Data_Attributes.Add "3130" Data_Attributes.Add "3131" Data_Attributes.Add "3132" Data_Attributes.Add "3133" Data_Attributes.Add "3134" Data_Attributes.Add "3135" Data_Attributes.Add "3140" Data_Attributes.Add "3141" Data_Attributes.Add "3142" Data_Attributes.Add "3143" Data_Attributes.Add "3144" Data_Attributes.Add "3145" Data_Attributes.Add "3150" Data_Attributes.Add "3151" Data_Attributes.Add "3152" Data_Attributes.Add "3153" Data_Attributes.Add "3154" Data_Attributes.Add "3155" Data_Attributes.Add "3160" Data_Attributes.Add "3161" Data_Attributes.Add "3162" Data_Attributes.Add "3163" Data_Attributes.Add "3164" Data_Attributes.Add "3165" Data_Attributes.Add "3200" Data_Attributes.Add "3201" Data_Attributes.Add "3202" Data_Attributes.Add "3203" Data_Attributes.Add "3204" Data_Attributes.Add "3205" Data_Attributes.Add "3210" Data_Attributes.Add "3211" Data_Attributes.Add "3212" Data_Attributes.Add "3213" Data_Attributes.Add "3214" Data_Attributes.Add "3215" Data_Attributes.Add "3220" Data_Attributes.Add "3221" Data_Attributes.Add "3222" Data_Attributes.Add "3223" Data_Attributes.Add "3224" Data_Attributes.Add "3225" Data_Attributes.Add "3230" Data_Attributes.Add "3231" Data_Attributes.Add "3232" Data_Attributes.Add "3233" Data_Attributes.Add "3234" Data_Attributes.Add "3235" Data_Attributes.Add "3240" Data_Attributes.Add "3241" Data_Attributes.Add "3242" Data_Attributes.Add "3243" Data_Attributes.Add "3244" Data_Attributes.Add "3245" Data_Attributes.Add "3250" Data_Attributes.Add "3251" Data_Attributes.Add "3252" Data_Attributes.Add "3253" Data_Attributes.Add "3254" Data_Attributes.Add "3255" Data_Attributes.Add "3260" Data_Attributes.Add "3261" Data_Attributes.Add "3262" Data_Attributes.Add "3263" Data_Attributes.Add "3264" Data_Attributes.Add "3265" Data_Attributes.Add "3270" Data_Attributes.Add "3271" Data_Attributes.Add "3272" Data_Attributes.Add "3273" Data_Attributes.Add "3274" Data_Attributes.Add "3275" Data_Attributes.Add "3280" Data_Attributes.Add "3281" Data_Attributes.Add "3282" Data_Attributes.Add "3283" Data_Attributes.Add "3284" Data_Attributes.Add "3285" Data_Attributes.Add "3290" Data_Attributes.Add "3291" Data_Attributes.Add "3292" Data_Attributes.Add "3293" Data_Attributes.Add "3294" Data_Attributes.Add "3295" Data_Attributes.Add "3300" Data_Attributes.Add "3301" Data_Attributes.Add "3302" Data_Attributes.Add "3303" Data_Attributes.Add "3304" Data_Attributes.Add "3305" Data_Attributes.Add "3310" Data_Attributes.Add "3311" Data_Attributes.Add "3312" Data_Attributes.Add "3313" Data_Attributes.Add "3314" Data_Attributes.Add "3315" Data_Attributes.Add "3320" Data_Attributes.Add "3321" Data_Attributes.Add "3322" Data_Attributes.Add "3323" Data_Attributes.Add "3324" Data_Attributes.Add "3325" Data_Attributes.Add "3330" Data_Attributes.Add "3331" Data_Attributes.Add "3332" Data_Attributes.Add "3333" Data_Attributes.Add "3334" Data_Attributes.Add "3335" Data_Attributes.Add "3340" Data_Attributes.Add "3341" Data_Attributes.Add "3342" Data_Attributes.Add "3343" Data_Attributes.Add "3344" Data_Attributes.Add "3345" Data_Attributes.Add "3350" Data_Attributes.Add "3351" Data_Attributes.Add "3352" Data_Attributes.Add "3353" Data_Attributes.Add "3354" Data_Attributes.Add "3355" Data_Attributes.Add "3360" Data_Attributes.Add "3361" Data_Attributes.Add "3362" Data_Attributes.Add "3363" Data_Attributes.Add "3364" Data_Attributes.Add "3365" Data_Attributes.Add "3370" Data_Attributes.Add "3371" Data_Attributes.Add "3372" Data_Attributes.Add "3373" Data_Attributes.Add "3374" Data_Attributes.Add "3375" Data_Attributes.Add "3400" Data_Attributes.Add "3401" Data_Attributes.Add "3402" Data_Attributes.Add "3403" Data_Attributes.Add "3404" Data_Attributes.Add "3405" Data_Attributes.Add "3410" Data_Attributes.Add "3411" Data_Attributes.Add "3412" Data_Attributes.Add "3413" Data_Attributes.Add "3414" Data_Attributes.Add "3415" Data_Attributes.Add "3420" Data_Attributes.Add "3421" Data_Attributes.Add "3422" Data_Attributes.Add "3423" Data_Attributes.Add "3424" Data_Attributes.Add "3425" Data_Attributes.Add "3430" Data_Attributes.Add "3431" Data_Attributes.Add "3432" Data_Attributes.Add "3433" Data_Attributes.Add "3434" Data_Attributes.Add "3435" Data_Attributes.Add "3440" Data_Attributes.Add "3441" Data_Attributes.Add "3442" Data_Attributes.Add "3443" Data_Attributes.Add "3444" Data_Attributes.Add "3445" Data_Attributes.Add "3450" Data_Attributes.Add "3451" Data_Attributes.Add "3452" Data_Attributes.Add "3453" Data_Attributes.Add "3454" Data_Attributes.Add "3455" Data_Attributes.Add "3460" Data_Attributes.Add "3461" Data_Attributes.Add "3462" Data_Attributes.Add "3463" Data_Attributes.Add "3464" Data_Attributes.Add "3465" Data_Attributes.Add "3470" Data_Attributes.Add "3471" Data_Attributes.Add "3472" Data_Attributes.Add "3473" Data_Attributes.Add "3474" Data_Attributes.Add "3475" Data_Attributes.Add "3480" Data_Attributes.Add "3481" Data_Attributes.Add "3482" Data_Attributes.Add "3483" Data_Attributes.Add "3484" Data_Attributes.Add "3485" Data_Attributes.Add "3490" Data_Attributes.Add "3491" Data_Attributes.Add "3492" Data_Attributes.Add "3493" Data_Attributes.Add "3494" Data_Attributes.Add "3495" Data_Attributes.Add "3500" Data_Attributes.Add "3501" Data_Attributes.Add "3502" Data_Attributes.Add "3503" Data_Attributes.Add "3504" Data_Attributes.Add "3505" Data_Attributes.Add "3510" Data_Attributes.Add "3511" Data_Attributes.Add "3512" Data_Attributes.Add "3513" Data_Attributes.Add "3514" Data_Attributes.Add "3515" Data_Attributes.Add "3520" Data_Attributes.Add "3521" Data_Attributes.Add "3522" Data_Attributes.Add "3523" Data_Attributes.Add "3524" Data_Attributes.Add "3525" Data_Attributes.Add "3530" Data_Attributes.Add "3531" Data_Attributes.Add "3532" Data_Attributes.Add "3533" Data_Attributes.Add "3534" Data_Attributes.Add "3535" Data_Attributes.Add "3540" Data_Attributes.Add "3541" Data_Attributes.Add "3542" Data_Attributes.Add "3543" Data_Attributes.Add "3544" Data_Attributes.Add "3545" Data_Attributes.Add "3550" Data_Attributes.Add "3551" Data_Attributes.Add "3552" Data_Attributes.Add "3553" Data_Attributes.Add "3554" Data_Attributes.Add "3555" Data_Attributes.Add "3560" Data_Attributes.Add "3561" Data_Attributes.Add "3562" Data_Attributes.Add "3563" Data_Attributes.Add "3564" Data_Attributes.Add "3565" Data_Attributes.Add "3570" Data_Attributes.Add "3571" Data_Attributes.Add "3572" Data_Attributes.Add "3573" Data_Attributes.Add "3574" Data_Attributes.Add "3575" Data_Attributes.Add "3600" Data_Attributes.Add "3601" Data_Attributes.Add "3602" Data_Attributes.Add "3603" Data_Attributes.Add "3604" Data_Attributes.Add "3605" Data_Attributes.Add "3610" Data_Attributes.Add "3611" Data_Attributes.Add "3612" Data_Attributes.Add "3613" Data_Attributes.Add "3614" Data_Attributes.Add "3615" Data_Attributes.Add "3620" Data_Attributes.Add "3621" Data_Attributes.Add "3622" Data_Attributes.Add "3623" Data_Attributes.Add "3624" Data_Attributes.Add "3625" Data_Attributes.Add "3630" Data_Attributes.Add "3631" Data_Attributes.Add "3632" Data_Attributes.Add "3633" Data_Attributes.Add "3634" Data_Attributes.Add "3635" Data_Attributes.Add "3640" Data_Attributes.Add "3641" Data_Attributes.Add "3642" Data_Attributes.Add "3643" Data_Attributes.Add "3644" Data_Attributes.Add "3645" Data_Attributes.Add "3650" Data_Attributes.Add "3651" Data_Attributes.Add "3652" Data_Attributes.Add "3653" Data_Attributes.Add "3654" Data_Attributes.Add "3655" Data_Attributes.Add "3660" Data_Attributes.Add "3661" Data_Attributes.Add "3662" Data_Attributes.Add "3663" Data_Attributes.Add "3664" Data_Attributes.Add "3665" Data_Attributes.Add "3670" Data_Attributes.Add "3671" Data_Attributes.Add "3672" Data_Attributes.Add "3673" Data_Attributes.Add "3674" Data_Attributes.Add "3675" Data_Attributes.Add "3680" Data_Attributes.Add "3681" Data_Attributes.Add "3682" Data_Attributes.Add "3683" Data_Attributes.Add "3684" Data_Attributes.Add "3685" Data_Attributes.Add "3690" Data_Attributes.Add "3691" Data_Attributes.Add "3692" Data_Attributes.Add "3693" Data_Attributes.Add "3694" Data_Attributes.Add "3695" Data_Attributes.Add "37" Data_Attributes.Add "3900" Data_Attributes.Add "3901" Data_Attributes.Add "3902" Data_Attributes.Add "3903" Data_Attributes.Add "3904" Data_Attributes.Add "3905" Data_Attributes.Add "3906" Data_Attributes.Add "3907" Data_Attributes.Add "3908" Data_Attributes.Add "3909" Data_Attributes.Add "3910" Data_Attributes.Add "3911" Data_Attributes.Add "3912" Data_Attributes.Add "3913" Data_Attributes.Add "3914" Data_Attributes.Add "3915" Data_Attributes.Add "3916" Data_Attributes.Add "3917" Data_Attributes.Add "3918" Data_Attributes.Add "3919" Data_Attributes.Add "3920" Data_Attributes.Add "3921" Data_Attributes.Add "3922" Data_Attributes.Add "3923" Data_Attributes.Add "3924" Data_Attributes.Add "3925" Data_Attributes.Add "3926" Data_Attributes.Add "3927" Data_Attributes.Add "3928" Data_Attributes.Add "3929" Data_Attributes.Add "3930" Data_Attributes.Add "3931" Data_Attributes.Add "3932" Data_Attributes.Add "3933" Data_Attributes.Add "3934" Data_Attributes.Add "3935" Data_Attributes.Add "3936" Data_Attributes.Add "3937" Data_Attributes.Add "3938" Data_Attributes.Add "3939" Data_Attributes.Add "3940" Data_Attributes.Add "3941" Data_Attributes.Add "3942" Data_Attributes.Add "3943" Data_Attributes.Add "3950" Data_Attributes.Add "3951" Data_Attributes.Add "3952" Data_Attributes.Add "3953" Data_Attributes.Add "3954" Data_Attributes.Add "3955" Data_Attributes.Add "3956" Data_Attributes.Add "3957" Data_Attributes.Add "3958" Data_Attributes.Add "3959" Data_Attributes.Add "400" Data_Attributes.Add "403" Data_Attributes.Add "410" Data_Attributes.Add "411" Data_Attributes.Add "412" Data_Attributes.Add "413" Data_Attributes.Add "416" Data_Attributes.Add "420" Data_Attributes.Add "421" Data_Attributes.Add "422" Data_Attributes.Add "423" Data_Attributes.Add "424" Data_Attributes.Add "425" Data_Attributes.Add "426" Data_Attributes.Add "427" Data_Attributes.Add "4300" Data_Attributes.Add "4301" Data_Attributes.Add "4302" Data_Attributes.Add "4303" Data_Attributes.Add "4304" Data_Attributes.Add "4305" Data_Attributes.Add "4306" Data_Attributes.Add "4307" Data_Attributes.Add "4308" Data_Attributes.Add "4309" Data_Attributes.Add "4310" Data_Attributes.Add "4311" Data_Attributes.Add "4312" Data_Attributes.Add "4313" Data_Attributes.Add "4314" Data_Attributes.Add "4315" Data_Attributes.Add "4316" Data_Attributes.Add "4317" Data_Attributes.Add "4318" Data_Attributes.Add "4319" Data_Attributes.Add "4320" Data_Attributes.Add "4321" Data_Attributes.Add "4322" Data_Attributes.Add "4323" Data_Attributes.Add "4324" Data_Attributes.Add "4325" Data_Attributes.Add "4326" Data_Attributes.Add "7001" Data_Attributes.Add "7002" Data_Attributes.Add "7003" Data_Attributes.Add "7004" Data_Attributes.Add "7005" Data_Attributes.Add "7006" Data_Attributes.Add "7007" Data_Attributes.Add "7008" Data_Attributes.Add "7009" Data_Attributes.Add "7010" Data_Attributes.Add "7011" Data_Attributes.Add "7020" Data_Attributes.Add "7021" Data_Attributes.Add "7022" Data_Attributes.Add "7023" Data_Attributes.Add "7030" Data_Attributes.Add "7031" Data_Attributes.Add "7032" Data_Attributes.Add "7033" Data_Attributes.Add "7034" Data_Attributes.Add "7035" Data_Attributes.Add "7036" Data_Attributes.Add "7037" Data_Attributes.Add "7038" Data_Attributes.Add "7039" Data_Attributes.Add "710" Data_Attributes.Add "711" Data_Attributes.Add "712" Data_Attributes.Add "713" Data_Attributes.Add "714" Data_Attributes.Add "715" Data_Attributes.Add "7230" Data_Attributes.Add "7231" Data_Attributes.Add "7232" Data_Attributes.Add "7233" Data_Attributes.Add "7234" Data_Attributes.Add "7235" Data_Attributes.Add "7236" Data_Attributes.Add "7237" Data_Attributes.Add "7238" Data_Attributes.Add "7239" Data_Attributes.Add "7240" Data_Attributes.Add "8001" Data_Attributes.Add "8002" Data_Attributes.Add "8005" Data_Attributes.Add "8007" Data_Attributes.Add "8008" Data_Attributes.Add "8009" Data_Attributes.Add "8012" Data_Attributes.Add "8026" Data_Attributes.Add "8110" Data_Attributes.Add "8111" Data_Attributes.Add "8112" Data_Attributes.Add "8200" Data_Attributes.Add "90" Data_Attributes.Add "91" Data_Attributes.Add "92" Data_Attributes.Add "93" Data_Attributes.Add "94" Data_Attributes.Add "95" Data_Attributes.Add "96" Data_Attributes.Add "97" Data_Attributes.Add "98" Data_Attributes.Add "99" For Each Data_Attribute In Data_Attributes If Data_Attribute = "240" Then MsgBox Data_Attribute & ", est présent dans la liste!" End If Next Data_Attribute End Sub
Je me suis mal exprimé.
Des collections de numéro d'AI, ça ne sert pas à grand-chose.
Ce qu'il faut stocker, c'est les éléments qui serviront à écrire l'url.
Première intention (mais p'tet pas le mieux, j'y reviens après)
Dans cette boucle de
Do boucleOut = False For Each pattern In patterns 'on teste chaque pattern pour le début du code regex.pattern = "^" + pattern If (regex.test(Code)) Then boucleOut = True ligne1 = "" 'si ça marche, on extrait la partie Set Match = regex.Execute(Code)(0) Set unCode = New unCode unCode.Init Match.SubMatches(0), Match.SubMatches(1) resultats.Add unCode 'on enlève ce qu'on vient de traiter Code = Replace(Code, Match.Value, "") 'et on recommence Exit For End If Next Loop While Len(Code) > 0 And boucleOut
En plus de mettre unCode dans la collection resultats, on pourrait tester l'AI avec un select case et le stocker aussi dans une des collections qui serviront ensuite à construire l'url.
Mais ça fait un second select case.
L'autre option est d'ajouter des attributs dans la classe unCode, IsPrimaryKeys, IsKeyQualifier et IsDataAttribute, que tu remplis dans le Select Case existant.
Et à la fin quand on écrit ligne 1 et ligne 2, on teste ces attributs et on écrit le cas échéant les 3 morceaux d'url.
PS, je débute aujourd'hui, une mission à 500km de chez moi jusqu'à mi mars.
J'aurais moins de temps en semaine et surtout les week-ends, je vais les consacrer à ma famille.
Je vais continuer à essayer de te donner des pistes, mais des codes entiers, ça sera plus difficile.
Bonjours,
Citation:
PS, je débute aujourd'hui, une mission à 500km de chez moi jusqu'à mi-mars.
J'aurais moins de temps en semaine et surtout les week-ends, je vais les consacrer à ma famille.
Je vais continuer à essayer de te donner des pistes, mais des codes entiers, ça sera plus difficile.
Je te souhaite réussite et satisfaction pour cette nouvelle mission!
Sans toi, ce projet n'en serait pas ou il en est!
Je serais patient avec mes difficultés.
Pour commencer j'ai fait un petit mémo des situations:
PrimaryKey seul:
(01)00607915137601
https://id.gs1.org/01/00607915137601
PrimaryKey + 1 KeyQualifier (sans IsDataAttribute):
(01)00607915137601(21)BBBBBBB
https://id.gs1.org/01/00607915137601/21/BBBBBBB
PrimaryKey (sans KeyQualifier) + 1 DataAttribute:
(01)00607915137601(17)230612
https://id.gs1.org/01/00607915137601?17=230612
PrimaryKey + 2 KeyQualifiers + 2 DataAttributes:
(01)00607915137601(11)230410(15)230511(17)230612(10)AAAAAA(21)BBBBBBB
https://id.gs1.org/01/00607915137601/10/AAAAAA/21/BBBBBBB?11=230410&15=230511&17=230612
Ensuite, au niveau de la classe unCode:
'Méthode qui retourne un texte sous la forme "https://id.gs1.org/Balise/LeCode" Public Function IsPrimaryKey() As String IsPrimaryKey = "https://id.gs1.org/" & AI & "/" & Code End Function
'Méthode qui retourne un texte sous la forme "/Balise/LeCode" Public Function IsKeyQualifier() As String IsKeyQualifier = "/" & AI & "/" & Code End Function
'Méthode qui retourne un texte sous la forme "Balise=LeCode" Public Function IsDataAttribute() As String IsDataAttribute = AI & "=" & Code End Function
La suite se complique.
Au niveau du Select Case comment exploiter?
Au niveau du module, création d'une ligne3 et ensuite l'appel aux case concernées?
Je suis un peu dans le flou.
Il y a aussi la gestion du point d'interrogation pour la fin de KeyQualifier, qu'il y en ai ou pas.
Et le séparateur de DataAttribute "&".
En général (et donc ça coulait de source pour moi), un attribut IsQuelqueChose est un boulean. Par exemple IsNumeric retourne si c'est un nombre ou pas.
Dans le select case de la classe, quand l'AI correspond à une PrimaryKey, tu mets True à IsPrimary et pareil pour les 2 autres.
Et là
'Dim primaryKey, ...., url as String ValidationData = True 'par défaut on considère que tout est correct For i = 1 To resultats.Count Set unCode = resultats(i) ligne1 = ligne1 + unCode.Texte ligne2 = ligne2 + vbCrLf + unCode.Description If unCode.ValidationData = False Then 's'il y a au moins une data incorrecte ça sera signalé ValidationData = False End If If unCode.IsPrimaryKey Then primaryKey = primaryKey + 'construction de la partie d'url qui correspond à cet AI End If 'Idem pour les 2 autres Next If ValidationData = False Then ligne2 = vbCrLf + vbCrLf + "Attention ça c'est mal passé !" + vbCrLf + ligne2 End If url = primaryKey + ... + ...
Public Function IsPrimaryKey() As Boolean
Ne passe pas!
J'ai utilisé Variant
Et là:
If unCode.IsPrimaryKey = True Then MsgBox "OK" End If
Ne me donne rien!
Il y a encore quelque chose que je n'ai pas compris.
C'est Bon je pense que j'y suis!
Pas besoin de fonction!
Public IsPrimaryKey As Boolean
Oui c'est ça
Bonsoir,
J'y suis presque!
Je ne sais pas comment gérer le point d'interrogation ?, qui marque la fin de keyQualifier.
Point d'interrogation, qui doit être présent quand il n'y a pas de keyQualifier mais, qu'il y a des dataAttribute (Point d'interrogation avant les dataAttribute).
Point d'interrogation est absent s'il n'y a pas de pas de dataAttribute après keyQualifier.
Les ajouts de la classe unCode:
Public IsPrimaryKey As Boolean Public IsKeyQualifier As Boolean Public IsDataAttribute As Boolean
Au niveau du Select Case (un exemple avec 3 AI, un de chaque groupe qui compose l'URL):
Case "01" madescription = "(01) N° ARTICLE (GTIN): " IsPrimaryKey = True Case "21" madescription = "(21) N° SÉRIE: " IsKeyQualifier = True Case "240" madescription = "(240) ID ADDITIONNEL: " IsDataAttribute = True
Le code du module:
Dim primaryKey, keyQualifier, dataAttribute, url As String ValidationData = True 'par défaut on considère que tout est correct For i = 1 To resultats.Count Set unCode = resultats(i) ligne1 = ligne1 + unCode.Texte ligne2 = ligne2 + unCode.Description + vbCrLf If unCode.ValidationData = False Then 's'il y a au moins une data incorrecte ça sera signalé ValidationData = False End If If unCode.IsPrimaryKey Then primaryKey = primaryKey + unCode.AI + "/" + unCode.Code 'construction de la partie d'url qui correspond à cet AI End If If unCode.IsKeyQualifier Then keyQualifier = keyQualifier + "/" + unCode.AI + "/" + unCode.Code 'construction de la partie d'url qui correspond à cet AI End If If unCode.IsDataAttribute Then dataAttribute = dataAttribute + "&" + unCode.AI + "=" + unCode.Code 'construction de la partie d'url qui correspond à cet AI End If Next If ValidationData = False Then ligne2 = vbCrLf + vbCrLf + "ATTENTION, vérifier les données de contrôle !" + vbCrLf + vbCrLf + ligne2 End If url = "https://id.gs1.org/" + primaryKey + keyQualifier + dataAttribute '+ ... + ... UserForm1.TextBox_Code_HRI = ligne1 UserForm1.TextBox_All_Data = ligne2 UserForm1.TextBox_Digital_Link_URI = url
Ci-dessous le résultat de plusieurs tests
En 1er ligne le code scanné
En 2eme ligne le code lisible par l'homme (HRI)
En 3eme ligne, l'url que j'obtiens
En 4eme ligne ce que donne le décodeur GS1
J'ai volontairement mis en évidence les balises de séparation " \x1d" en les remplaçants par <GS>.
PrimaryKey seul:
]d20109420012407221
(01)09420012407221
https://id.gs1.org/01/09420012407221
https://id.gs1.org/01/09420012407221
PrimaryKey + dataAttribute:
]C101008838738677921122092717230927
(01)00883873867792(11)220927(17)230927
https://id.gs1.org/01/00883873867792&11=220927&17=230927
https://id.gs1.org/01/00883873867792?11=220927&17=230927
PrimaryKey + keyQualifier:
]C1010088387386779210220927<GS>21PC23713163
(01)00883873867792(10)220927(21)PC23713163
https://id.gs1.org/01/00883873867792/10/220927/21/PC23713163
https://id.gs1.org/01/00883873867792/10/220927/21/PC23713163
PrimaryKey + keyQualifier + dataAttribute:
]C10100883873867792112209271723092710220927<GS>21PC23713163
(01)00883873867792(11)220707(17)230707(10)220707(21)PC22412085
https://id.gs1.org/01/00883873867792/10/220707/21/PC22412085&11=220707&17=230707
https://id.gs1.org/01/00883873867792/10/220707/21/PC22412085?11=220707&17=230707
Bonsoir
en #154 tu as écrit
Suivi d'un point d'interrogation ?, qui marque la fin de Key qualifiers (AI)
Le point d'interrogation ? doit être présent même s'il n'y a pas de Key qualifiers (AI)
....
Suivi de l'esperluette & s'il y a plusieurs "Data attributes (AI)" à la suite.
Donc c'est après les KeyQualifier qu'il faut le mettre.
Par contre, il ne faut pas mettre de & au tout début de la construction des dataAttribute, mais à partir du second
Pas testé
For i = 1 To resultats.Count Set unCode = resultats(i) ligne1 = ligne1 + unCode.Texte ligne2 = ligne2 + unCode.Description + vbCrLf If unCode.ValidationData = False Then 's'il y a au moins une data incorrecte ça sera signalé ValidationData = False End If If unCode.IsPrimaryKey Then primaryKey = primaryKey + unCode.AI + "/" + unCode.Code 'construction de la partie d'url qui correspond à cet AI End If If unCode.IsKeyQualifier Then keyQualifier = keyQualifier + "/" + unCode.AI + "/" + unCode.Code 'construction de la partie d'url qui correspond à cet AI End If If unCode.IsDataAttribute Then If dataAttribute <> "" Then dataAttribute = dataAttribute + "&" 'si y'a déjà un data attribute End If dataAttribute = dataAttribute + unCode.AI + "=" + unCode.Code 'construction de la partie d'url qui correspond à cet AI End If Next If ValidationData = False Then ligne2 = vbCrLf + vbCrLf + "ATTENTION, vérifier les données de contrôle !" + vbCrLf + vbCrLf + ligne2 End If Url = "https://id.gs1.org/" + primaryKey + keyQualifier + "?" + dataAttribute
Bonsoir,
Dans mon poste précédent, j'apporte plus d'informations.
Citation:
Le point d'interrogation ?, qui marque la fin de keyQualifier.
Point d'interrogation, qui doit être présent quand il n'y a pas de keyQualifier mais, qu'il y a des dataAttribute (Point d'interrogation avant les dataAttribute).
Point d'interrogation est absent s'il n'y a pas de pas de dataAttribute après keyQualifier.
Je peux ajouter que ce point d'interrogation est absent si primaryKey est seul.
Cas où c'est bon:
]C101008838738677921122092717230927
(01)00883873867792(11)220927(17)230927
https://id.gs1.org/01/00883873867792?11=220927&17=230927
]C1010088387386779211220927172309271022092721PC23713163
(01)00883873867792(11)220707(17)230707(10)220707(21)PC22412085
https://id.gs1.org/01/00883873867792/10/220927/21/PC23713163?11=220927&17=230927
Cas où ce n'est pas bon:
]d20109420012407221
(01)09420012407221
https://id.gs1.org/01/09420012407221 ?
]C101008838738677921022092721PC23713163
(01)00883873867792(10)220927(21)PC23713163
https://id.gs1.org/01/00883873867792/10/220927/21/PC23713163 ?
Le 1er cas où ce n'est pas bon c'est primaryKey est seul.
Le 2eme c'est keyQualifier sans dataAttribute.
Ça complique les choses!
J'essaie de supprimer le point d'interrogation de l'url avant affichage s'il est à la fin, mais je ne trouve pas la bonne méthode.
Vu qu'on est dans les RegEx, une possibilité:
Function Extract_Caractere(Caractere_A_Extraire As String) As String With CreateObject("vbscript.regexp") .Global = True .Pattern = "(\?)$" Extract_Caractere = .Replace(Caractere_A_Extraire, "") End With End Function
Idéalement ou effectuais-tu l'action?
Heu... là, t'as copié collé mon dernier code sans le regarder ?
OK, j'avais raté l'info qu'il ne devait pas y avoir de ? si pas de dataAttribute, mais c'est exactement pareil que le &.
Y'a un cas où il le faut et un ou il ne le faut pas.
Je l'avais bien vu!
If unCode.IsDataAttribute Then If dataAttribute <> "" Then dataAttribute = dataAttribute + "&" 'si y'a déjà un data attribute End If dataAttribute = dataAttribute + unCode.AI + "=" + unCode.Code 'construction de la partie d'url qui correspond à cet AI End If
Je n'ai pas réussi à l'adapter, car comme évoqué précédemment, il y a 2 cas de figure ou le point d'interrogation doit être absent:
1) Si primaryKey seul.
(01)09420012407221
https://id.gs1.org/01/09420012407221"?"
2) Si pas de dataAttribute
(01)00883873867792(10)220927(21)PC23713163
https://id.gs1.org/01/00883873867792/10/220927/21/PC23713163"?"
Comme c'est OK dans tous les autres cas et que le point d'interrogation est ajouté à la construction de l'url, j'ai pensé que ce serait plus simple de le supprimer, car il est toujours en fin d'url quand c'est l'un de ces 2 cas.
1) ne peut être validé que si 2).
Donc la clé c'est 2).
On peut donc appliquer la même chose que pour le "&"
url = partie1 + partie2
Si partie3 n'est pas vide => url = url + "?" + partie3
Désolé, mais je ne percute vraiment pas!
Je pourrais me contenter du code ci-dessous ou je supprime le point d'interrogation via RegEx, code qui semble répondre à toutes les conditions, mais j'aimerais vraiment comprendre.
A noté que j'ai adapté ta solution pour primaryKey, car je suis tombé sur un cas où il y avait 2 primaryKey.
Mais, pour le point d'interrogation je ne visualise pas du tout et toutes mes tentatives sont un échec!
Dim ValidationData As Boolean Dim primaryKey, keyQualifier, dataAttribute, url As String ValidationData = True 'par défaut on considère que tout est correct For i = 1 To resultats.Count Set unCode = resultats(i) ligne1 = ligne1 + unCode.Texte ligne2 = ligne2 + unCode.Description + vbCrLf If unCode.ValidationData = False Then 's'il y a au moins une data incorrecte ça sera signalé ValidationData = False End If If unCode.IsPrimaryKey Then If primaryKey <> "" Then primaryKey = primaryKey + "/" 'si y'a déjà un primaryKey End If primaryKey = primaryKey + unCode.AI + "/" + unCode.Code 'construction de la partie d'url qui correspond aux AIs "primaryKey" End If If unCode.IsKeyQualifier Then keyQualifier = keyQualifier + "/" + unCode.AI + "/" + unCode.Code 'construction de la partie d'url qui correspond aux AIs "keyQualifier" End If If unCode.IsDataAttribute Then If dataAttribute <> "" Then dataAttribute = dataAttribute + "&" 'si y'a déjà un data attribute End If dataAttribute = dataAttribute + unCode.AI + "=" + unCode.Code 'construction de la partie d'url qui correspond aux AIs "dataAttribute" End If Next If ValidationData = False Then ligne2 = vbCrLf + vbCrLf + "ATTENTION, vérifier les données de contrôle !" + vbCrLf + vbCrLf + ligne2 End If url = "https://id.gs1.org/" + primaryKey + keyQualifier + "?" + dataAttribute regex.pattern = "(\?)$" UserForm1.TextBox_Code_HRI = ligne1 UserForm1.TextBox_All_Data = ligne2 'UserForm1.TextBox_Digital_Link_URI = url UserForm1.TextBox_Digital_Link_URI = regex.Replace(url, "")
Bonsoir,
Je ne pensais pas que la gestion des dates serait aussi complexe!
Comme pour le CheckSum, j'ai regardé comment traiter la validité des dates contenue dans certains AI.
1er problème, le format des dates "US" sur 6 chiffres soit : YYMMDD
Le test suivant me confirme que je ne suis pas dans le bon format:
Sub test() Dim textDate As String textDate = "140585" ''textDate = "231123" textDate = Format(textDate, "00\/00\/00") Dim realDate As Date realDate = DateValue(textDate) Debug.Print realDate '<~ returns 14/05/1985 End Sub
Résultat respectif:
14/05/1985
23/11/2023
Soit: DDMMYY
Apparemment il serait possible de remédier à ce problème via les paramètres régionaux:
https://stackoverflow.com/questions/51620085/change-region-format-to-another-language-with-vba
Là j'avoue être complétement dépassé par le code ci-dessus.
La documentation "gs1-syntax-dictionary" donne 3 codes en C que je ne sais pas lire!
Ils peuvent peut-être aider?
-yymmd0
https://gs1.github.io/gs1-syntax-dictionary/lint__yymmd0_8c.html
-yymmdd
https://gs1.github.io/gs1-syntax-dictionary/lint__yymmdd_8c.html
-yymmddhh
https://gs1.github.io/gs1-syntax-dictionary/lint__yymmddhh_8c.html
J'ai fait un petit récapitulatif des AIs qui utilisent ces codes et de la position du traitement:
N6,yymmdd
AI: 4326, 7006
-
N6,yymmdd N4,hhmm
AI: 7003
-
N6,yymmdd [N6],yymmdd
AI: 7007
-
N6,yymmdd [N4],hhmm
AI: 7001
-
N8,yymmddhh [N..4]
AI: 8008
-
N6,yymmd0
AI: 11, 12, 13, 15, 16, 17
-
N6,yymmd0 N4,hhmm
AI: 4324, 4325
-
Une idée de comment gérer ces dates en VBA?
Bonjour
alors oui les dates c'est un sérieux problème, et encore 140585, c'est facile, si on admet qu'il n'y a que des yymmdd ou des ddmmyy
Il suffit de découper en 3 groupes de 2 chiffres, celui du milieu c'est toujours le mois, ensuite on constate que 85 est supérieur à 31 donc forcément c'est l'année, celui qui reste le jour.
Évidemment si on commence à supposer qu'on peut aussi avoir yyddmm ou mmddyy, 140585 n'est plus interprétable.
Et que dire de 100811 ?
Tu peux y appliquer tous les algorithmes que tu veux, tous les formats sont possibles impossible sans autre information de choisir le bon.
Les codes en C présupposent que le format est yymmdd
Selon la documentation GS1, les dates sont toujours au format YYMMDD (Année sur 2 chiffres en 1er, suivit du moi sur 2 chiffres, puis jour sur 2 chiffres).
Si cette règle n'est pas respectée, pas de contrôle de date valide, juste un avertissement de non-conformité avec GS1.
En gérant à partir de 2000 vu que ces dates sont des dates de production, de garantie, de péremption, de livraison …) et en considèrent que la durée de vie moyenne d'un article est de 15 ans, on devrait être dans les clous.
Dans cette logique, 100811 donne 2010/08/11
Je ne parviens pas à coder quelque chose qui donne ce résultat!
Je suis bloqué sur la résolution:
YYMMDD = YYYYMMDD
La suite pourrait être géré de cette façon:
Option Explicit Function validExcelDate(num As Long) As Boolean Dim Y As Long, M As Long, D As Long Dim leapYr As Boolean Dim dt1904 As Boolean dt1904 = ThisWorkbook.Date1904 'Would also be valid year if test passed If num < IIf(dt1904, 19040101, 19000101) _ Or num > 99991231 Then Exit Function 'special case If num = 19000229 Then validExcelDate = True Exit Function End If D = num Mod 100 M = Int((num Mod 10000) / 100) Y = Int(num / 10000) 'valid month If M < 1 Or M > 12 Then Exit Function 'valid day If D < 1 Then Exit Function leapYr = LY(Y) Select Case M Case 4, 6, 9, 11 If D > 30 Then Exit Function Case 2 If D > 29 Then Exit Function If leapYr = False And D > 28 Then Exit Function Case Else If D > 31 Then Exit Function End Select validExcelDate = True End Function Private Function LY(yr As Long) As Boolean If yr / 4 = Int(yr / 4) And _ Not (yr / 100 = Int(yr / 100)) Then _ LY = True If yr / 400 = Int(yr / 400) Then LY = True End Function
Résultat OK pour 20231129
L'ajout des slashs peut être faite après!
Le problème est " ThisWorkbook.Date1904" applicable à une feuille.
Je n'ai pas trouvé d'équivalant pour une variable!