I have the following byte array.
Dim Template(1023) As Byte
Then i call the fingerprint scanner device function and returns the following:
duplicate:
Convert hex value to a decimal value in VB6
from Andre Laszlo:
Dim hexVal as String
hexVal = "#7B19AB"
Dim intVal as Integer
intVal = Val("&H" & Replace(hexVal, "#", ""))
Fancy version tolerant of manual entry:
Private Function BytesToHex(ByRef Bytes() As Byte) As String
'Quick and dirty Byte array to hex String, format:
'
' "HH HH HH"
Dim LB As Long
Dim ByteCount As Long
Dim BytePos As Integer
LB = LBound(Bytes)
ByteCount = UBound(Bytes) - LB + 1
If ByteCount < 1 Then Exit Function
BytesToHex = Space$(3 * (ByteCount - 1) + 2)
For BytePos = LB To UBound(Bytes)
Mid$(BytesToHex, 3 * (BytePos - LB) + 1, 2) = _
Right$("0" & Hex$(Bytes(BytePos)), 2)
Next
End Function
Private Function HexToBytes(ByVal HexString As String) As Byte()
'Quick and dirty hex String to Byte array. Accepts:
'
' "HH HH HH"
' "HHHHHH"
' "H HH H"
' "HH,HH, HH" and so on.
Dim Bytes() As Byte
Dim HexPos As Integer
Dim HexDigit As Integer
Dim BytePos As Integer
Dim Digits As Integer
ReDim Bytes(Len(HexString) \ 2) 'Initial estimate.
For HexPos = 1 To Len(HexString)
HexDigit = InStr("0123456789ABCDEF", _
UCase$(Mid$(HexString, HexPos, 1))) - 1
If HexDigit >= 0 Then
If BytePos > UBound(Bytes) Then
'Add some room, we'll add room for 4 more to decrease
'how often we end up doing this expensive step:
ReDim Preserve Bytes(UBound(Bytes) + 4)
End If
Bytes(BytePos) = Bytes(BytePos) * &H10 + HexDigit
Digits = Digits + 1
End If
If Digits = 2 Or HexDigit < 0 Then
If Digits > 0 Then BytePos = BytePos + 1
Digits = 0
End If
Next
If Digits = 0 Then BytePos = BytePos - 1
If BytePos < 0 Then
Bytes = "" 'Empty.
Else
ReDim Preserve Bytes(BytePos)
End If
HexToBytes = Bytes
End Function