バイナリで開いたデータを
10 の部分を 34 55 66 に
書き換えたいのですが、どうすればいいのでしょうか?
Replaceでやろうとしましたが、出来ませんでした。
ちなみにソースは、
Dim bytGetData() As Byte
Dim Writebin() As Byte
Dim RepS() As Byte
Dim RepM() As Byte
Dim fn As Long
Dim strFile1 As String
strFile1 = App.Path & "\bin.dat"
fn = FileLen(strFile1)
ReDim bytGetData(fn)
fn = FreeFile
Open strFile1 For Binary As #fn
Get #fn, , bytGetData
Close #fn
RepS = StrConv(Chr$(&H10), vbFromUnicode)
RepM = StrConv(Chr$(&H34) & Chr$(&H55) & Chr$(&H66), vbFromUnicode)
Writebin = Replace(bytGetData, RepS, RepM)
fn = FreeFile
Open strFile1 For Binary As #fn
Put #fn, , Writebin
Close #fn
です。よろしくお願いします。
私ならこうします。
Dim i As Long
Dim bytGetData As Byte
Dim bytRep(2) As Byte
Dim fn1 As Integer
Dim fn2 As Integer
Dim strFile1 As String
Dim strFile2 As String
bytRep(0) = &H34
bytRep(1) = &H55
bytRep(2) = &H66
strFile1 = App.Path & "\bin.dat"
strFile2 = App.Path & "\bin.tmp"
fn1 = FreeFile
Open strFile1 For Binary Access Read As #fn1
fn2 = FreeFile
Open strFile2 For Binary Access Write As #fn2
For i = 1 To LOF(fn1)
Get #fn1, , bytGetData
If bytGetData = &H10 Then
Put #fn2, , bytRep
Else
Put #fn2, , bytGetData
End If
Next
Close #fn1
Close #fn2
Kill strFile1
Name strFile2 As strFile1
batchman様、ありがとうございます。無事に解決しました。
バイナリのデータを1つずつ見ていけば良かったのですね。