I want to check the arrangement of data in this order from byte 49 to mFile size(END OF FILE).
04 FF _ _ _ _ _04 FF _ _ _ _ 04 FF _ _.
_ __ 04 FF _ _ _ _ 04 FF _ _ _ _ 04 FF
Actually the values in the hex form. Each value represents 1 byte. Actually I already open the file in the binary editor using VB code. I would like to check the arrangement of data from byte 49 to MFileSize. If the code detect other than this 2 values ,I want to change it straight way to 04 FF.using the for loop i would like it check the data by i+5 it mean it go to 5th palce and check again until end of file.Someone please help me
This is my coding - Private cmd check _click( )
-
Dim a as integer
-
Dim b as string
-
a=4
-
b=FF
-
-
For i=49 to MfileSize
-
If
-
arrByte(i)<>a
-
then a=4
-
end if
-
i=i+5
-
Next
-
-
-
-
-
For i=50 to mFileSize
-
If arrByte(i) <> FF
-
Then
-
b=FF
-
Endif
-
i=i+5
-
next
5 1270
I think you need to study your basic programming concepts a bit more. In particular, the use of variables. Take this code... - If arrByte(i) <> a Then
-
a = 4
-
End If
This code does absolutely nothing, because a is already equal to 4. a is not what you want to change.
Try this one for size... - Private Sub check_click()
-
Const a As Byte = 4
-
Const b As Byte = &HFF
-
Dim i As Long
-
-
For i = 49 To mFileSize Step 7
-
If arrByte(i) <> a Then
-
arrByte(i) = a
-
End If
-
If arrByte(i + 1) <> b Then
-
arrByte(i + 1) = b
-
End If
-
Next
-
End Sub
Note, as far as I can see this is only changing the array arrByte, not the actual file. If you want this data back in the file, you will probably have to write it there afterward. (Unless there's some sort of link I'm not aware of between the array and the file.)
I checked out your other posts, to get a better idea of what you're trying to do. This version should so what you want (I think) but I haven't tested it. One nice feature is that it will show you what it's doing, as it goes (just printing to the immediate window).
In any such situation, when changing data like this, I highly recommend keeping a backup copy of the input file, or writing the output to a different file. You should always be able to go back or start over if something goes wrong. - Private Sub check_click()
-
Const a As Byte = 4
-
Const b As Byte = &HFF
-
Dim i As Long
-
Dim AnyChanged As Boolean
-
Dim ChangeMade As Boolean
-
-
For i = 49 To mFileSize Step 6
-
AnyChanged = False
-
Debug.Print "Before : "; Hex$(arrByte(i)); " "; Hex$(arrByte(i + 1)); " "; Hex$(arrByte(i + 2)); _
-
" "; Hex$(arrByte(i + 3)); " "; Hex$(arrByte(i + 3)); " "; Hex$(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 : "; Hex$(arrByte(i)); " "; Hex$(arrByte(i + 1)); " "; Hex$(arrByte(i + 2)); _
-
" "; Hex$(arrByte(i + 3)); " "; Hex$(arrByte(i + 3)); " "; Hex$(arrByte(i + 5)); _
-
" <--- Corrected"
-
Beep
-
End If
-
Debug.Print
-
Next
-
-
' At this point, variable AnyChanged tells you whether any
-
' corrections were made, and thus whether you need to write
-
' arrByte() back to the file.
-
-
End Sub
Thank You Sir For Ur Help.im Not So Good In Programming But Ur Guide Realy Help Me Sir.thank You Very Much.thanks For Spent Ur Time To Guide Me Sir.
By the way, you may find that the output looks a bit nasty because the hex values are sometimes one character, sometimes two. Just in case it's useful, here's an old function I wrote which will display the Hex value as a fixed number of characters. To use it, just plug it into any code module and then any time you want to print a byte value as two hex digits, just print HexByte2Char(value) - Public Function HexByte2Char(ByVal Value As Byte) As String
-
HexByte2Char = IIf(Value < &H10, "0", "") & Hex$(Value)
-
End Function
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Duane Lambe |
last post by:
I'll start out by saying that I've been looking for a definitive
answer for a few hours now, and need opinions on this one.
I have a site I've been starting for our internal helpdesk joint....
|
by: Kurt Watson |
last post by:
I’m having a different kind of problem with Hotmail when I sign in it
says, "Web Browser Software Limitations
Your Current Software Will Limit Your Ability to Use Hotmail
You are using a web...
|
by: Jason |
last post by:
Hi,
I was wondering if any could point me to an example or give me ideas on how
to dynamically create a form based on a database table? So, I would have a
table designed to tell my application...
|
by: Carlo, MCP |
last post by:
Hi,
Sorry for posting twice, but I hope in your comprehension. Please help me!
I'm troubling from months with a serious serialization problem that I'm not
able to solve. I try to describe as...
|
by: David Van D |
last post by:
Hi there,
A few weeks until I begin my journey towards a degree in Computer
Science at Canterbury University in New Zealand,
Anyway the course tutors are going to be teaching us JAVA wth bluej...
|
by: funfair |
last post by:
HI,EVERY ONE
first problem,
i have create a database in access 2003 it worked fine untill i have
format my laptop .
now im working on office 2003 on windows xp and i have norton 2006 but
im...
|
by: oldgent |
last post by:
I am having a problem installing the starter kits. I have reinstalled VS
2005, think that might be the problem. I then installed both 'Personal
Website" and the "Club Website" starter kits. I...
|
by: PEB |
last post by:
POSTING GUIDELINES
Please follow these guidelines when posting questions
Post your question in a relevant forum
Do NOT PM questions to individual experts - This is not fair on them and...
|
by: icetalks |
last post by:
have a look at this code , its for logging the user in after checking his UserName and Password.
dim check as boolean = false
...
...
If txtUserName.Text.Length = 0 And txtPass.Text.Length =...
|
by: luap |
last post by:
Hello good friends, please i need your help and advice on how i should best programme the problem, if possible a different option to solve it is welcomed.
The problem a matching problem, how to...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
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,...
| |