473,699 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How To Rewrite The Corrected Value

kirubagari
158 New Member
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 1400
Killer42
8,435 Recognized Expert Expert
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_Fi le 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 New Member
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 Recognized Expert Expert
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 New Member
Public Sub ReWrite_Open_Fi le(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(ar rByte(i)); " "; HexByte2Char(ar rByte(i + 1)); " "; HexByte2Char(ar rByte(i + 2)); _
" "; HexByte2Char(ar rByte(i + 3)); " "; HexByte2Char(ar rByte(i + 4)); " "; HexByte2Char(ar rByte(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(ar rByte(i)); " "; HexByte2Char(ar rByte(i + 1)); " "; HexByte2Char(ar rByte(i + 2)); _
" "; HexByte2Char(ar rByte(i + 3)); " "; HexByte2Char(ar rByte(i + 4)); " "; HexByte2Char(ar rByte(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 Recognized Expert Expert
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 New Member
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 New Member
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 Recognized Expert Expert
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 New Member
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

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

Similar topics

16
25873
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
1347
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
1812
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 seves as t the 'one' side of one-to-many relationship. Enter a record in the 'one' side table with the desired key value, and then make the entry with the desired join key in the 'many-only' table."
188
7179
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 - non-deterministic destructors - Objects can't exist on the stack - Type / Reference Types
6
1966
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 can be Nothing but not in the sense of a object reference to Nothing ... rather, you supposedly can use an equality comparison MyControl.Date = Nothing
1
2122
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 www.yoursite.com/products/ListProductsByCategory.aspx?CategoryID=1 will result in a partial missing of images and css which are packaged inside products folder. and if I rewrite from www.yoursite.com/products/beverages.aspx to
14
1812
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 decide whether they should rewrite their app in .NET. What are the trends being observed of Microsoft when it comes to .Net? How much longer will COM objects live on? How stable is the Framework?
1
3069
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 of apache is in picture the fethced value is not correct. say the rule i am using in rewrite.conf is RewriteRule ^/ows/printenv$ http://10.152.70.206:9999/cgi-bin/printenv.pl?map=public.map what is seen is if i access ^/ows/printenv apache...
6
1445
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
8623
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9197
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9054
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8941
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7785
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5881
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4390
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3071
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2362
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.