Hi all, How do I change bytes [text stored in those bytes] in a binary file?
I have a little function that read bytes 335-343 [For Keyer] and bytes 344-352 [for verifier] and displays it. These bytes store who the keyerID and VerifierID of a data entry file are. From time to time the Verifier Resumes the file [to insert new records], and his/her name gets stored in the KeyerID bytes. So if the original keyer had lots of errors, the new verifier now becomes the owner of this file and the errors are attributed to him/her [not fair]. He/She gets penalized when there are lots of errors.
My question to you is, how do I change the content of those bytes and save it to the file, without damaging any part of the file? I want to save 'H345' in those bytes, [H345 is an example of a Keyer/Verifier ID]
note - as of now I am using 010 Editor [binary editor]to manually change those bytes. When I use this editor, I can see the text portions for those bytes.
I am using vb.net 2008Here is the function I use to find out who the keyer and Verifier of the date entry file are.
Sub FindInfoFromFile(ByRef strFileToCheck As String) Dim bYes As Boolean Dim strOpName As String = "" Dim strVerName As String = "" Dim strKeyer As String = "" Dim strVerifier As String = "" Dim strFileFlag As String = "" Dim intMyPos As Short Dim intMyPos2 As Short On Error GoTo ErrorHandler If strFileToCheck <> "" Then Fname = Fname & strFileToCheck strOpName = "" strVerName = "" strFileFlag = "" sNewFile = Fname Using fs As New FileStream(sNewFile, FileMode.Open) Dim strOutofBFlag As String = "" Using br As New BinaryReader(fs) 'Check The file type to see it it is an ezc file fs.Position = 0 'For x As Integer = 1 To 2 strFileFlag &= br.ReadChar 'Next If strFileFlag <> "d" Then 'Exit the loop because this is not an ezc file MsgBox("Invalid File Type Being Checked: " & sNewFile) GoTo ExitFileCheck End If fs.Position = 335 'Get Keyers Name - this info is stored in bytes 335 to 344 For x As Integer = 335 To 343 strOpName &= br.ReadChar Next x 'Verifier are bytes 344-352 fs.Position = 344 For x As Integer = 344 To 352 strVerName &= br.ReadChar Next x End Using End Using 'Parse the Keyers name by removing unwanted characters intMyPos2 = 0 intMyPos2 = FindNonBlankPos(strOpName, Chr(0)) strKeyer = Mid(strOpName, 1, intMyPos2 - 1) Text5.Text = strKeyer 'Parse the Verifyer name by removing unwanted characters intMyPos2 = 0 intMyPos2 = FindNonBlankPos(strVerName, Chr(0)) strVerifier = Mid(strVerName, 1, intMyPos2 - 1) 'Text8.Text = StatusDB.GetNameByEmpID(strVerifier) Text8.Text = strVerifier End If ExitFileCheck: ExitHere: Exit Sub ErrorHandler: Select Case Err.Number Case 5 MsgBox("Invalid File Type " & Err.Number & " :-: " & Err.Description) 'Resume Next Case Else 'cout Err.Number & Err.Description, endl Call HandleUnexpectedError(Err.Number, Err.Description) End Select Resume ExitHere 'GoTo ExitHere Resume Next End Sub
Thanks in advance
Edited 3 Years Ago by Dani: Formatting fixed