Convertir une macro en fonction
Bonjour,
Je cherche a convertir une macro en fonction.
Loin d'etre un pro de la programmation, j'aurai besoin d'un coup de main ...
La macro fonctionne, mais quand j'essaye de la convertir, j'ai une erreur "#valeur!"
Pour info, la macro calcul le CRC16 d'une table de caracteres.
Ci dessous le code "transformé"
D'avance, merci de votre aide !
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| '-------------------------------------------------
Public Function ModCRC(Buffer() As Variant) As Long
'-------------------------------------------------
Dim CRC1 As Variant
Dim J As Integer
Dim K As Long
Dim c As Long
Dim l As Long
Application.Volatile
CRC1 = &HFFFF ' init CRC
For l = 1 To UBound(Buffer) ' pour chaque mot (2 octets par mot)
c = 1 ' init index colonne
While c < 3
CRC1 = CRC1 Xor Buffer(l, c)
For J = 0 To 7 ' pour chaque bit dans l'octet
K = CRC1 And 1 ' memorisation du bit de poid faible
CRC1 = ((CRC1 And &HFFFE) / 2) And &H7FFF ' decalage à droite apres masquage du bit de poid faible
If K > 0 Then CRC1 = CRC1 Xor &HA001
Next J ' bit suivant
c = c + 1
Wend
Next l ' mot suivant
ModCRC = CRC1
End Function |