想写个程序二进制形式打开某个文件,寻找其中的日期数据并修改为指定日期,问了好多人一直没搞定,希望高手帮忙。
最后写成这个样子:
Private Type DateValue
v As Date
End Type
Private Type ByteArray
a(7) As Byte
End Type
Private Sub Command1_Click()
Dim Data() As Long
Dim d() As Byte
Dim dt As DateValue, ba As ByteArray
Dim i As Long
dt.v = Text1.Text 'Text1.Text中为文件中已知的的日期
LSet ba = dt
For i = 0 To 7
Text2.Text = Text2.Text & Hex(ba.a(i))'将Text1.Text中日期转换成hex存入text2.text
Next
End SubPrivate Sub Command2_Click()
Dim d As ByteArray
With CommonDialog1
.Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer
.Filter = ("所有文件|*.*")
.ShowOpen
End With
FN = CommonDialog1.FileName
F = FreeFile
Open FN For Binary As F
While Not EOF(F)
Get F, i, d
If d = Text2.Text Then '运行到这里出错
MsgBox "OK"
End If
i = i + 1
Wend
Close F
End Sub
替换为指定日期的功能还没有添加,请大家帮忙!
最后写成这个样子:
Private Type DateValue
v As Date
End Type
Private Type ByteArray
a(7) As Byte
End Type
Private Sub Command1_Click()
Dim Data() As Long
Dim d() As Byte
Dim dt As DateValue, ba As ByteArray
Dim i As Long
dt.v = Text1.Text 'Text1.Text中为文件中已知的的日期
LSet ba = dt
For i = 0 To 7
Text2.Text = Text2.Text & Hex(ba.a(i))'将Text1.Text中日期转换成hex存入text2.text
Next
End SubPrivate Sub Command2_Click()
Dim d As ByteArray
With CommonDialog1
.Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer
.Filter = ("所有文件|*.*")
.ShowOpen
End With
FN = CommonDialog1.FileName
F = FreeFile
Open FN For Binary As F
While Not EOF(F)
Get F, i, d
If d = Text2.Text Then '运行到这里出错
MsgBox "OK"
End If
i = i + 1
Wend
Close F
End Sub
替换为指定日期的功能还没有添加,请大家帮忙!
Option Explicit
Private Type DateValue
v As Date
End Type
Private Type ByteArray
a(7) As Byte
End Type
Private Sub Command1_Click()
Dim Data() As Long
Dim d() As Byte
Dim dt As DateValue, ba As ByteArray
Dim i As Long
dt.v = Text1.Text 'Text1.Text中为文件中已知的的日期
LSet ba = dt Text2.Text = GetText(ba.a)End SubPrivate Sub Command2_Click()
Dim d As ByteArray
Dim FN As String
Dim F As Long
Dim i As Long
i = 1
With CommonDialog1
.Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer
.Filter = ("所有文件 |*.*")
.ShowOpen
End With
FN = CommonDialog1.FileName
F = FreeFile
Open FN For Binary As F
While Not EOF(F)
Get F, i, d
If GetText(d.a) = Text2.Text Then '运行到这里出错
MsgBox "OK"
End If
i = i + 1
Wend
Close F
End SubPrivate Function GetText(ByRef a() As Byte) As String
Dim i As Long
For i = 0 To 7
GetText = GetText & Hex(a(i))
Next
End Function'我调试的时候,没有出现错误,但是不知能不能找到结果.
那我现在要想把找到的数据替换成我指定的数据该怎么办呢,用put循环写入吗,还有没有更好的方法?
没有必要再进行循环一次.
Dim d As ByteArray
With CommonDialog1
.Flags = cdlOFNHideReadOnly Or cdlOFNAllowMultiselect Or cdlOFNExplorer
.Filter = ("所有文件 ¦*.*")
.ShowOpen
End With
FN = CommonDialog1.FileName
F = FreeFile
Open FN For Binary As F
While Not EOF(F)
Get F, i, d
dim myDate as date
copymemory mydate,d,8 '记住要申明API
If cstr(mydate) = Text2.Text Then
MsgBox "OK"
End If
i = i + 1
Wend
Close F
End Sub
替换为指定日期的功能还没有