Bytearray from richtextbox hex

No_Comment
08-26-2009, 08:12 AM
I want to create a bytearray from a richtextbox just like a bytearray will be created here:

Dim bytearr As Byte
Open "c:\test.exe" For Binary As #1
ReDim bvTmp(LOF(1) - 1)
Get #1, , bytearr
Close #1

But in this application i want the result in the bytearray to be the same as in the code above

http://img228.imageshack.us/img228/6194/hex2.jpg

Dim bytearr() As Byte
bytearr() = HexToString(r1.Text)

With this Function:

Public Function HexToString(ByVal HexToStr As String) As String
Dim strTemp As String
Dim strReturn As String
Dim I As Long
For I = 1 To Len(HexToStr) Step 2
strTemp = Chr$(Val("&H" & Mid$(HexToStr, I, 2)))
strReturn = strReturn & strTemp
Next I
HexToString = strReturn
End Function

But it's not the same. Can someone please help me out.

kassyopeia
08-26-2009, 12:18 PM
There is no need to turn the hex string into a char string and then into a byte array, you can do it directly. Something like (rough draft)

For I = 1 To Len(HexToStr) \ 2
byteArr(I) = CByte("&H" & Mid$(HexToStr, I*2, 2))
Next I

should work just fine.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum