5/5 (7 avis)
Snippet vu 37 545 fois - Téléchargée 38 fois
Function stringtobyte(ByVal str As String, data() As Byte) ReDim data(Len(str)) For i = 1 To Len(str) data(i - 1) = Asc(Mid(str, i, 1)) Next i End Function Public Function ByteToString(ByRef bInput() As Byte) As String Dim i As Long ByteToString = "" i = 0 Do While i < UBound(bInput) + 1 ByteToString = ByteToString + Chr$(bInput(i)) i = i + 1 Loop End Function Function stringtohex(ByVal str As String) As String ReDim data(Len(str)) For i = 1 To Len(str) stringtohex = stringtohex & Hex(Asc(Mid(str, i, 1))) Next i End Function Public Function hexToString(ByRef str As String) As String Dim i As Long hexToString = "" i = 1 Do While i < Len(str) hexToString = hexToString & Chr$(Hextodec(Val(Mid(str, i, 2)))) i = i + 2 Loop End Function Public Function Hextodec(ByVal Nombre As String) CoeffMulti = 1 Operation = 0 For x = Len(Nombre) To 1 Step -1 Select Case UCase(Mid(Nombre, x, 1)) Case "A" Number = 10 Case "B" Number = 11 Case "C" Number = 12 Case "D" Number = 13 Case "E" Number = 14 Case "F" Number = 15 Case Else If Asc(Mid(Nombre, x, 1)) > 47 And Asc(Mid(Nombre, x, 1)) < 58 Then Number = Mid(Nombre, x, 1) Else Exit Function End If End Select Number = Number * CoeffMulti Operation = Operation + Number CoeffMulti = CoeffMulti * 16 Next x Hextodec = Operation End Function Public Function bytetohex(buffer() As Byte) As String bytetohex = vbNullString For i = 0 To UBound(buffer) bytetohex = bytetohex & Hex(buffer(i)) Next i End Function Public Function hextobyte(ByVal str As String, buffer() As Byte) Dim i As Long ReDim buffer(Len(str)) hextobyte = vbNullString i = 1 a = 0 Do While i < UBound(buffer) buffer(a) = Hextodec(Val(Mid(str, i, 2))) i = i + 2 a = a + 1 Loop End Function
18 oct. 2009 à 18:51
Que La bataille commence ! :)
29 juil. 2008 à 12:17
Ubound retourne la borne supérieure du tableau (et non sa taille).
Il ne faut donc pas mettre le "-1" ...
19 juin 2006 à 14:27
23 mars 2006 à 16:45
Public Function bytetohex(buffer() As Byte) As String
bytetohex = vbNullString
For I = 0 To UBound(buffer) - 1 'Il faut ajouter le - 1 sinon la fonct ajoute un
'zero en fin de chaine!
bytetohex = bytetohex & Hex(buffer(I))
Next I
End Function
Merci pour le coup de main, joli resumé de fonctions! a+
24 déc. 2004 à 14:48
voir mon code sous :
http://www.vbfrance.com/code.aspx?ID=28389
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.