[CODE=vb]Public Sub ReWrite_Open_Fi le(ByVal FileNo As Long)
Dim FileSize As Long, Buffer() As Byte
' PART 1: Read the file.
FileSize = LOF(FileNo) ' Determine how large the file is (in bytes).
ReDim Buffer(1 To FileSize) ' Set our buffer to that length.
Get #FileNo, 1, Buffer() ' Grab the entire file's data into the array
' PART 2
' If you plan to change the data, this is where it would happen.
'Beep
' PART 3: Write the file back.
If MsgBox("Write data back to the file?", vbYesNo) = vbYes Then
Put #FileNo, 1, Buffer() ' Write the data back to the file.
End If
End Sub
Private Sub Command2_Click( )
Dim mHandle
mHandle = FreeFile
Open "a:\bonding.bin " For Binary Access Read Write Lock Write As mHandle
ReWrite_Open_Fi le mHandle
End Sub[/CODE]
Why this function is not working? This function can execute but it can't overwrite after it changes the valus. I mean after it checked the value from byte 49 to mfile, if there is error it will check and correct the value. I want make it after it correct the value, it overwrite the file with the correct value.
For eg:
05 FF 45 65 78 65
04 FF 45 65 78 65<-----CORRECTED (Want to overwrite the file after it changed the value to
correct value)
65 54 65 34 76 89
04 FF 65 34 76 89<-----CORRECTED (same)
I think you all can understand my problem
Dim FileSize As Long, Buffer() As Byte
' PART 1: Read the file.
FileSize = LOF(FileNo) ' Determine how large the file is (in bytes).
ReDim Buffer(1 To FileSize) ' Set our buffer to that length.
Get #FileNo, 1, Buffer() ' Grab the entire file's data into the array
' PART 2
' If you plan to change the data, this is where it would happen.
'Beep
' PART 3: Write the file back.
If MsgBox("Write data back to the file?", vbYesNo) = vbYes Then
Put #FileNo, 1, Buffer() ' Write the data back to the file.
End If
End Sub
Private Sub Command2_Click( )
Dim mHandle
mHandle = FreeFile
Open "a:\bonding.bin " For Binary Access Read Write Lock Write As mHandle
ReWrite_Open_Fi le mHandle
End Sub[/CODE]
Why this function is not working? This function can execute but it can't overwrite after it changes the valus. I mean after it checked the value from byte 49 to mfile, if there is error it will check and correct the value. I want make it after it correct the value, it overwrite the file with the correct value.
For eg:
05 FF 45 65 78 65
04 FF 45 65 78 65<-----CORRECTED (Want to overwrite the file after it changed the value to
correct value)
65 54 65 34 76 89
04 FF 65 34 76 89<-----CORRECTED (same)
I think you all can understand my problem
Comment