I do not know exactly what you mean with your second question, but the info I found here might proof useful:
http://msdn.microsoft.com/
Main Topics
Browse All TopicsHello.
I have two questions:
1. How to delete record from file opened with Random access?
2. How to put a binary data (*.bmp, *.gif, *.exe) in random access opened file and to be usefull after reading again. I tried but it only works when the file is opened in binary mode but then I can only get one (first) record written in file. Is there a way to make file in binary mode to work like file in random mode when reading records?
Thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I do not know exactly what you mean with your second question, but the info I found here might proof useful:
http://msdn.microsoft.com/
In second question I will like to know is there a way to for example do next:
1. open some (bmp, jpg, exe...) file for binary access read as #1 and get its contents
2. open second file for random as #1 and put content of first file in second like standard record wich can be later used properly?
OR IF THIS IS NOT POSSIBLE THEN:
Is there a way to manage records in binary file mode like in random?
The problem with your second question is that image files are not the same length, therefore you cannot access them via a recordnumber because you don't know where one record ends and the next begins as in a typical random access file.
The only way to do this would be to create your own custom header to store the byte position and length of each image in the file just as a Zip file would.
~IM
To do what you want to do with Binary information of variable size you will need to set up some large fixed Byte array to store each set of Binary information into and also store the size. That is not a good way to do it.
It would be better if you just opened the file as Binary and stored a seek point at the beginning of each chunk of binary data (or keep the seek points in a seperate file). Maybe store the seek point of the Previous/Next record. For instance, create a record like this.
Public Type BLOBHeaderType
BLOBValid As Boolean
BLOBSeek As Long
BLOBSize As Long
PrevSeek As Long
NextSeek As Long
End Type
Rather then Delete anything you can simply mark it as Invalid by BLOBValid = False. Programitically ignore any chunk of data that has BLOBValid set to False. If you must conserve disk space you can write a function that compacts the file getting rid of any data that has BLOBValid set to False, but that doesn't need to be done on the fly. Only when things get too large.
Technically, you don't need a BLOBSeek point since you know that it must start a right after the record. So you could just get the record size and advance you file pointer. But I just threw it in if you would rather use it. You also don't need a BLOBSize since the BLOB size is the NextSeek minus the BLOBSeek point. But again, you might as well just store that information rather then compute it.
Now, all you do is the following.
Open the file for Binary and get the file pointer to the end of the file
You do this by walking through the file reading the headers and jumping to the NextSeek point.
It is important that you remember the last seek point so you can put it into PrevSeek of the new record.
Save the last seek point into PrevSeek after you reach the end of the file.
Save the current seek point into another variable called CurrHeaderSeek
You will need that so that you can come back and rewrite this record after you fill it up with real data.
But for now Write a dummy BLOBHeader to the file (just to make room for it).
Save the new current seek point into BLOBSeek (in your header record)
Save the size of the binary data in your BLOBSize (in your header record)
Write the Binary data to the file
Save the new current seek point into NextSeek (in your header record)
Set the BLOBValid to True (in your header record)
Seek back to the dummy BLOBHeader (that is seek back to CurrHeaderSeek)
Resave the proper BLOBHeader that we filled up nicely.
Now, what you probably want to do is add more information about each BLOB to the BLOBHeader record. Like if this is JPG's then maybe the JPG name or some other such information that might be useful to the user.
Still, in general the above is probably the way to go. No, actually the way to go would be to toss your BLOBs into a DB (like Access or Personal SQL Server or whatever).
You know you could also jump to the end of the file directly. However, you still need to know the Previous seek point. So, you could always save a dummy record at the end of the file whose data was all junk except for the PrevSeek value. That way, you could just jump to the end of the file and then move back the size of a record and read just that dummy record (that already has the PrevSeek value set properly). That is probably the way I would do it since I don't like the idea of walking through the entire file (particularly if it is large). Just more for you to consider.
In other words, add this last step to the above.
Save CurrHeaderSeek into a dummy BLOBHeader and save it to the end of the file.
And instead of reading through the entire file you would do the following.
Open the file for Binary.
Move to the end of the file minus the BLOBHeader size.
Read in the working BLOBHeader that contains the PrevSeek value already set.
Mind you you will have to handle the special case when the file is first created (empty file). But that shouldn't be a problem.
It's a clever system and definitely doable.
I don't think you need BLOBSeek, or BLOBSize for that matter, since after you read that structure, the file pointer will already be sitting in the BLOB data waiting for the next read. To read the structure, you would already have it defined, and consequently know the size.
~IM
By BLOB I meant the Binary portion that followed the structure. You will need to know that in order to indicate the number of bytes to read. But you are correct that you can figure out the number of bytes based on the value of NextSeek (with a bit of fudging). Basicly the file will look something like this (assuming three JPG's or whatever)
BLOBHeader1
Binary Data1 of Arbitrary Size
BLOBHeader2
Binary Data2 of Arbitrary Size
BLOBHeader3
Binary Data3 of Arbitrary Size
BLOBHeader4
Were,
BLOBHeader1.BLOBValid = True
BLOBHeader1.BLOBSeek = Seek of Binary Data1 (as mentioned this can be calculated)
BLOBHeader1.BLOBSize = Byte count for Binary Data1 (as well, this can be calculated)
BLOBHeader1.PrevSeek = -1
BLOBHeader1.NextSeek = Seek of BLOBHeader2
BLOBHeader2.BLOBValid = True
BLOBHeader2.BLOBSeek = Seek of Binary Data2 (as mentioned this can be calculated)
BLOBHeader2.BLOBSize = Byte count for Binary Data2 (as well, this can be calculated)
BLOBHeader2.PrevSeek = Seek of BLOBHeader1
BLOBHeader2.NextSeek = Seek of BLOBHeader3
BLOBHeader3.BLOBValid = True
BLOBHeader3.BLOBSeek = Seek of Binary Data3 (as mentioned this can be calculated)
BLOBHeader3.BLOBSize = Byte count for Binary Data3 (as well, this can be calculated)
BLOBHeader3.PrevSeek = Seek of BLOBHeader2
BLOBHeader3.NextSeek = Seek of BLOBHeader4
And of course, to make this more efficient you would store a trailing dummy BLOBHeader like this:
BLOBHeader4.BLOBValid = False
BLOBHeader4.BLOBSeek = -1
BLOBHeader4.BLOBSize = -1
BLOBHeader4.PrevSeek = Seek of BLOBHeader3
BLOBHeader4.NextSeek = -1
Now to delete a BLOB you would simply mark its BLOBValid value as False. Then when you read through the file you would ignore any BLOBs that had BLOBValid of False.
Then to compress the file and eliminate any False valued BLOBValid BLOBs you could do what osmodean recommended (copy each BLOBValid True BLOB to a seperate file ignoring any False BLOBs and then adjust the Seek values in each BLOBHeader).
Now, if you are up for a more of a challange there are more interesting ways of eliminating the False BLOBs from your file. This is to say that you could consolidate the True BLOBs to the begining of the file and then keep track of the extra space created by the void at the end of the file (overwritting it with new True BLOBs). As well, this is not so bad since you can move BLOBs as a chunk (since you know the entire size of the BLOBHeader and BLOB Binary data). This will be much faster then simply moving one byte at a time (by which I mean, having VB read and write one byte at a time). But that is another lesson (interesting as it is).
Oh, I think that there might be a few minor pitfalls to using VB records that I should mention. Depending on the types of data that you are storing in the record you might end up getting a bit of padding at the end of each record. This is to say that you might end up with a byte or two extra at the end of each record (in the file itself). That is important if you want to know the actual size of the record in the file (not in memory). I mention this without thinking about it in any way. It might not be a problem, it might be a problem, if I thought more about it I could tell you. I only mention it just in case you toy with this idea and find that you are having trouble locating the next record or locating the Binary data (depending on how you get the Seek values, that is, whether you ask VB for it or whether you calculate it based on the memory sizes of the records (which is sometimes different then the actual size on disk)). Just a thought....that I didn't have....cause I didn't think about....what you might want to think about....if you encounter such a problem..... :)
Idle_Mind: I think that what I said above is pretty much what you were suggesting in your message. Wish I had read your message so that it could have saved me time on typing....hee hee.
Actually, I read the question and then left my desk for a bit then came back and answered it without doing a refresh. That'll learn me.
Business Accounts
Answer for Membership
by: osmodeanPosted on 2004-12-07 at 10:36:22ID: 12766801
Deleting Records
library/de fault.asp? url=/libra ry/ en-us/v bcon98/htm l/vbconusi ngrandomfi leaccess.a sp
You could delete a record by clearing its fields, but the record would still exist in the file. Usually you dont want empty records in your file, because they waste space and interfere with sequential operations. It is better to copy the remaining records to a new file, and then delete the old file.
To remove a deleted record in a random-access file
1. Create a new file.
2. Copy all the valid records from the original file into the new file.
3. Close the original file and use the Kill statement to delete it.
4. Use the Name statement to rename the new file with the name of the original file.
Source: http://msdn.microsoft.com/