Voicis quelques fonctions de conversion bien pratiques, la fonction hextodec n'est pas de moi, mais je ne trouve plus l'auteur. Merci a lui
Source / Exemple :
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
Conclusion :
pour stringtobyte, appelez la avec call stringtobyte...
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.