So you want to convert that hex string to binary format of a file, so you can save it to a binary file......This functioin HexToDec converts Hex values into decimal or denary values, then you can store it in a byte array which you can then use to output the converted hex to a binary file...Put the following function either on the form or in a module...VB Code:
Private Sub Command1_Click Dim Fno as Integer Dim ByteArray() As Byte dim i as Integer Fno = FreeFile For i = 0 To Len(HEXString) ByteArray(i) = HexToDec(Mid(HEXString, i, 1)) Next i 'Save it to file Open "c:\something.exe" For Binary As #Fno Put #Fno, , ByteArray Close #Fno End SubReplace the filename with your file, and replace HEXString with your hex string variableVB Code:
Public Function HexToDec(ByVal HexStr As String) As Double Dim mult As Double Dim DecNum As Double Dim ch As String Dim i As Integer mult = 1 DecNum = 0 For i = Len(HexStr) To 1 Step -1 ch = Mid(HexStr, i, 1) If (ch >= "0") And (ch <= "9") Then DecNum = DecNum + (Val(ch) * mult) Else If (ch >= "A") And (ch <= "F") Then DecNum = DecNum + ((Asc(ch) - Asc("A") + 10) * mult) Else If (ch >= "a") And (ch <= "f") Then DecNum = DecNum + ((Asc(ch) - Asc("a") + 10) * mult) Else HexToDec = 0 Exit Function End If End If End If mult = mult * 16 Next i HexToDec = DecNum End Function![]()




Reply With Quote