1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
Public Function Read_Hex(file_name As String, offset As Long, size As Integer) As String
On Error GoTo erro
Dim ROM As Long
Dim i As Integer
Dim data As Byte
Dim data1 As String
ROM = FreeFile
Open file_name For Binary As ROM
For i = 1 To size
Get ROM, offset + i, data
data1 = data1 & Right$("00" & Hex(data), 2)
Next
Read_Hex = Right("000000000000" & data1, size * 2)
Close ROM
Exit Function
erro:
MsgBox Err.Description, vbOKOnly, "Error: " & Err.Number
End Function
Public Function WriteHex(file_name As String, offset As Integer, size As Integer, data As String) As Boolean
On Error GoTo erro
Dim ROM As Long
Dim data1 As String
Dim data2 As Byte
ROM = FreeFile
Open file_name For Binary As ROM
offset = offset + 1
'data1 = Hex(data)
Do While (Len(data1) Mod 2 <> 0)
data = "0" & data
Loop
'Do While Len(data) > 0
Do While data <> ""
data2 = Val("&H" & Mid(data, 1, 2))
Put ROM, offset, data2
data = Right$(data1, Len(data) - 2)
offset = offset + 1
Loop
Close ROM
Exit Function
erro:
MsgBox Err.Description, vbOKOnly, "Error: " & Err.Number
End Function
|