Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Want to use vb to search a hex file, and create a hex file

Status
Not open for further replies.

bjherron

IS-IT--Management
Joined
Jan 27, 2003
Messages
5
Location
US
Here's a very short description of what I want to do.

I would like to be able to open a 224K hex file, and split that file into four seperate 56K files. The trick is that I need to search the 224K file for hex patterns to know how it will be split up. For example, I know that the first file will begin with the data 27 FE OC, and the following 56K of data needs to go into the first split up file. Once I find the starting point for each of the 56K files, I want to copy that 56K into seperate files.

I have used VB to write MS access integrated programs, but I haven't done much with file creation. Can anyone provide some tips or a rough idea of how I should proceed?

Thanks,
Brian
 
I'm confused. Either your file is broken up into 56k blocks or it uses this binary pattern to delimit the sections.

Either way you need to open the file up for binary read.

Sounds to me as if you should just read 56k into a byte array then write it out to a file, read the next 56k into the byte array and write it out, etc

look up FreeFile() as it will show you the Open command too.
 
basically I have one 224k file that I need split into four seperate files. Each of the four files will be 56K, and as an additional requirment, the 224K file won't always have the data in the same order. That's why I need to search thru it first, to find where I should start reading each of the 4 chunks I want to suck out.

I'll look up the FreeFile(), thanks for the tip.
 
ah
ok I'd say read the full file into a large byte array and just loop through it fast to find the first value you are looking for. If you find it "27" or decimal 39 then check the next 2 bytes.
if it matches grab write that block of 56k bytes to a file.
 
I agree with SemperFi that byte arrays and binary files are the two structures that will be at the heart of the solution.

But I'm not sure how best to use these structures. You have a 224K file which you must break up into 4 56K files, with each partition beginning with a certain sequence.

If the file is evenly segmented between the four partitions (0-55K, 56-111K, 112K-167K, and 168K-223K) but you don't know the order, then you know exactly where each 56K partition begins, you only need to which partition is where. In this case, I would read the file into 4 56K byte arrays, then looking at the first three elements of each array to determine to order in which to write the array's out.

If its not balanced, then I have to ask the following questions: If a partition can start anywhere, and starts less than 56K from the end of the file, does it wrap back to the beginning? Or do you pad it, and if so, with what? What do you do with data that comes before the starting position? Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
thank you for the help. I understand what you are saying, so I'll see if I can implement it. The last 56K file will have to be padded with 7F values at the end.

How exactly do I open a file in binary? I need to buy a better book :(

sorry for so many questions!
Brian
 
I figured out how to select the file and open it, but i am having difficulties defining the correct array type and loading it in. I did a seach on FreeFile, but I couldn't find any examples of it used in similar situations.

I apprecaite your time!
Brian
 
FreeFile is only a function that returns an available File handle
If you don't have VBHelp, there is always MSDN:
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
To define a byte array, a dim statement similar to the following would be used:

Dim ByteArray(249856) As Byte

To open the binary file, and read from it, the code would be similar to the following:

Dim iHnd as Integer
lInt_Hnd = FreeFile
Open "C:\dir1\dir2\file" For Binary As iHnd

And to read from the file starting in the first position and populating the entire array would be the following:

Get #1, 1, ByteArray

To read the 2nd 56K partition, the following would work

Dim Part2(57344) as Byte
Get #1, 57345, Part2 Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top