I have been given the following code to convert a string to a "byte array" (which is then passed to other software) but it does not appear to work. I have practically never needed to use a function and am even less familiar with the data type byte and Hex numbers. I think the Val("&H") + Mid$(QueryStr, ByteIndex * 2 + 1, 2) part is wrong (Very!). Any clues?
Type DATAQUERY
Data(SP_MAX_QUERY_SIZE - 1) As Byte
End Type
Global Const SP_MAX_QUERY_SIZE = 56
************************
The first QueryStr is "0C65450C"
I think QueryLength is 8.
************************
Public Function StringToDataQuery(QueryStr As String, QueryLength As Integer) As DATAQUERY
'This converts the query string to a query byte array
Dim ByteIndex As Integer
ByteIndex = 0
For ByteIndex = 0 To QueryLength - 1
StringToDataQuery.Data(ByteIndex) = _
Val("&H") + Mid$(QueryStr, ByteIndex * 2 + 1, 2)
Next ByteIndex
End Function