473,408 Members | 2,832 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

How To Rewrite The Corrected Value

kirubagari
158 100+
Expand|Select|Wrap|Line Numbers
  1. Public Sub ReWrite_Open_File(ByVal FileNo As Long)
  2.   Dim FileSize As Long, Buffer() As Byte
  3.   ' PART 1: Read the file.
  4.   FileSize = LOF(FileNo) ' Determine how large the file is (in bytes).
  5.   ReDim Buffer(1 To FileSize) ' Set our buffer to that length.
  6.   Get #FileNo, 1, Buffer() ' Grab the entire file's data into the array
  7.   ' PART 2
  8.   ' If you plan to change the data, this is where it would happen.
  9.   'Beep
  10.  
  11.   ' PART 3: Write the file back.
  12.   If MsgBox("Write data back to the file?", vbYesNo) = vbYes Then
  13.     Put #FileNo, 1, Buffer() ' Write the data back to the file.
  14.   End If
  15. End Sub
  16.  
  17.  
  18. Private Sub Command2_Click()
  19. Dim mHandle
  20. mHandle = FreeFile
  21. Open "a:\bonding.bin" For Binary Access Read Write Lock Write As mHandle
  22. ReWrite_Open_File mHandle
  23. End Sub
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
Jul 23 '07 #1
11 1385
Killer42
8,435 Expert 8TB
This sub was written to demonstrate methods of reading and writing the data to/from the file in binary mode. As written, it doesn't actually achieve anything useful. It simply reads the entire file into an array, then immediately writes the array straight straight back to the file. The only visible result of this will be a new last-updated date/time on the file.

I've just tested it (for the first time), and it does appear to successfully re-write the file in place.

What you need to do is perform your correction to the array at the point labelled PART 2, so that the data written back to the file includes the corrections. In other words, the overall process would be to read the file into the array, correct the array, then write it back to the file.

You can do this in a number of ways, including:
  • Insert your data-correction code into the ReWrite_Open_File routine at "PART 2".
  • Place your data-correction code in a separate Sub and call it at the point labelled "PART 2".
  • (The preferred option) Incorporate the demonstrated file reading and writing techniques into your own code. As you can see, the actual file access is very simple.
Jul 23 '07 #2
kirubagari
158 100+
Killer42 i actualy cant understand what you are saying.But i can understand that the correction also translate into array whwn it write back data in to the file.Can u give me some examples so that i can understand and proceed with this problem
Jul 23 '07 #3
Killer42
8,435 Expert 8TB
I don't know whether I can really explain it much more simply. The overall process is this...
  1. You open the file.
  2. You read the data from the file (into a byte array, in this case).
  3. You write the data back to the file (from the byte array).
  4. You close the file.
Somewhere between steps 3 and 4 in this process, you need to make your corrections to the data held in the array. Otherwise, you are just putting back in the file the same information which was already there.

The only meaningful change I could make in the routine as posted would be a call to some routine of yours which does the correction to the array, at the point labelled "PART 2". If you still can't get it to work, try playing around with it for a while. After all, including your correction to the array, you've really only got those five simple "blocks" to stick together. There are only so many ways you can logically do it.
Jul 23 '07 #4
kirubagari
158 100+
Public Sub ReWrite_Open_File(ByVal FileNo As Long)
Dim FileSize As Long, Buffer() As Byte

Const a As Byte = 4
Const b As Byte = &HFF
Dim i As Long
Dim AnyChanged As Boolean
Dim changeMade As Boolean

' 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
For i = 1 To 567 Step 6
AnyChanged = False
Debug.Print "Before : "; HexByte2Char(arrByte(i)); " "; HexByte2Char(arrByte(i + 1)); " "; HexByte2Char(arrByte(i + 2)); _
" "; HexByte2Char(arrByte(i + 3)); " "; HexByte2Char(arrByte(i + 4)); " "; HexByte2Char(arrByte(i + 5))


If arrByte(i) <> a Then
arrByte(i) = a
changeMade = True

End If
If arrByte(i + 1) <> b Then
arrByte(i + 1) = b
changeMade = True
End If
If changeMade Then
AnyChanged = True
Debug.Print "After : "; HexByte2Char(arrByte(i)); " "; HexByte2Char(arrByte(i + 1)); " "; HexByte2Char(arrByte(i + 2)); _
" "; HexByte2Char(arrByte(i + 3)); " "; HexByte2Char(arrByte(i + 4)); " "; HexByte2Char(arrByte(i + 5))


End If
Next








' 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


killer42 i can understand what you are trying to say.So i try put the byte correction function in the part2.So is it can work?But it doesnt work.So previously u ask me to put the byte correction in the part 2.I put the function over there.Am i have to change the coding or can used the same coding
Jul 23 '07 #5
Killer42
8,435 Expert 8TB
Two questions.
  1. What do you mean, exactly, by "doesn't work"? I can't tell what's going on if you don't give me details.
  2. I see your FOR loop goes from 1 to 567. I thought you were starting from 49?
Jul 23 '07 #6
kirubagari
158 100+
ya its starting from 49 to mfile size.I mistakenly type the ting.Just now i test the data from 1 byte until 597.I give the wrong coding to you.Sorry

Actualy i put the code in the part2,but it does not work out.The thing cant overwrite.I do no weather im doing correct or not.....
Jul 23 '07 #7
kirubagari
158 100+
Doesnt work mean the things cant overwrite after it orrect the data from byte 49 to mfilesize.Why it cant overwrite
Jul 23 '07 #8
Killer42
8,435 Expert 8TB
Doesnt work mean the things cant overwrite after it orrect the data from byte 49 to mfilesize.Why it cant overwrite
Can you explain in more detail what you mean when you say it can't overwrite? I know that the read/write code works, having tested it myself a couple of hours ago. So perhaps your floppy disk is write-protected or something?
Jul 23 '07 #9
kirubagari
158 100+
This is some of the attachment that help you all understand my problem.The floppy is not write protected.When I change the data manually it can save the new byte.
Jul 23 '07 #10
kirubagari
158 100+
killer 42 please help on this
Jul 24 '07 #11
Killer42
8,435 Expert 8TB
killer 42 please help on this
It's getting hard to do so, because this is split into so many separate threads. I did respond, in this thread, as did another expert.

I think you need to stick to one thread while you work through this thing, so we can all keep track of where we're going. I'm completely confused now about where things stand.

In debugging program code, you need to slow down and tackle one thing at a time. One of the most important concepts to keep in mind when debugging is to accurately identify and isolate the problem.

So, tell me this. If you just use the supplied code to read the file into the array and write it back, does the file come out exactly the same, but with the modified date/time updated? If so, then you know you can concentrate on the corrections being done within the array. If not, then we can ignore the array modification, because it makes no difference what we do to the array if we are not going to record it accurately.
Jul 24 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Douglas | last post by:
Gday, How would I format a number so that: TheValue = 32500 Displays in the TextBox as: $32,500.00
1
by: bdwise | last post by:
Is it possible to rewrite the URI shown in the browser "Address" bar using JavaScript? That way, during a <form> POST, the "Address" information could be captured too. Thanks.
2
by: Susan Bricker | last post by:
I went back to read my post and found an error in my description ... here is the post, again, corrected: The following error: "The current field must match the join key '?' in the table that...
188
by: christopher diggins | last post by:
I have posted a C# critique at http://www.heron-language.com/c-sharp-critique.html. To summarize I bring up the following issues : - unsafe code - attributes - garbage collection -...
6
by: John A Grandy | last post by:
how are people dealing with the situation where a function accepts a String representation of a date ... but a control on the page or form returns a Date value ... strangely, these Date values...
1
by: baroque Chou | last post by:
Thanks for the help available on msdn, I have succesful done the rewrite job. But there are 2 problems arise: 1.when I try to rewrite the url from say: www.yoursite.com/beverages.aspx to...
14
by: Stan Canepa | last post by:
This post is mostly for discussion. Why rewrite in .NET? Just a general discussion not related to any specific details. I was just looking to see what reasons developers are looking to, to help...
1
by: soniamuk | last post by:
i am facing a typical issue with apache where i have a filter context(written in c++) which pulls information from apache server. in this process when i am trying to fetch an url where rewrite rule...
6
by: greenxiar | last post by:
How to get the function from "rewrited interface implement"? interface I { int Value { get; } } class A : I { int I.Value { get { return 1; } } } class B : I { int I.Value { get { return 2;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.