that depends entirely on how the data is stored in the flat file... the problem with flatfiles, is that they are sequential. So, at the very least, you are going to have to loop through the lines in the file, until you find your record, remove your record, and re-write everything before (and after) your record. That's just how it goes with flatfiles. You don't really HAVE to, you could write your code so that if it finds a blank line during processing, that it just ignores it, but you are looking at mad database bloat. If you had written the file as "binary", then you could add and remove records without having to go through each line.... but with a flat-file, you pretty much have to.
actually i think i need to know just how to refer to each record individually, ie what do i need to be able to refer to each record considering each has a unique number to each record, which is a piece of data within the record, can i just use this??
In a flat file a comma, a space, or a tab is usually used to separate the fields in a record. You have one record per line.
So, your file--if indeed it is a flat file--should look something like this in Notepad:
1, George, Jungle, #02/05/07#, 800-Jungle
2, Jane, WildWoman, #02/05/08#, 1-800-ClimbATree
you can use spaces, tabs, colons, whatever to delimit fields.
But you should test every line as you read it for the data that you want to delete. I would use the Instr() function as tool to find the date that you wish to delete. But your program first has to save the search criteria to use it in your code. Just load the ID of the record that you want to delete into a variable: I'll leave that to you.
And use that variable in your Instr function.
Dim LinesFromFile as String, NextLine as String
Dim strTest as String, strId as String, strDelimiter as string
Dim strExtracted as String
Dim lngDelimiterPosition as long
strDelimiter = ","
Do Until EOF(FileNum)
Line Input #FileNum, NextLine
lngDelimiterPosition = Instr(1, NextLine, strDelimiter, vbTextCompare)
' Isolate just the ID
strExtracted = left(NextLine, lngDelimiterPosition - 1)
if strID <> strExtracted then
LinesFromFile = LinesFromFile + NextLine + Chr(13) + Chr(10)
This will read every line in the file. But you probably have no other choice. But being that it's at least a Pentium class machine. This would probably take less than a second or two anyway.
This code should leave out the data you wish to delete in the LinesFromFile string. You'll have to do a little investigation on how to work with files. This example uses the old file commands.
thanks for that il give it a try!
one more thing though how do i refer to each line ie the name line how does the program know which one it is there must be some kind of reference, thanks
In a flat file you just loop through the whole file or quit the loop depending on a search criteria.
How does the program know? The programmer has to have some idea of how the data is organized: usually it's by the first field in the line. For example:
1, George, Jungle, 1 800 MonkeyMan
1 would be the value of the first field. But the programmer has to extract this data by using code. Or he can use the Indexed Sequential Access Method (ISAM) drivers that come with the Microsoft Jet Database Engine and use the Microsoft Jet Database methods to work with the data. But I don't know what your instructor is requiring you to do. More than likely he would be content, if you just used a loop test like I have given.
But in designing databases you usually try to have at least one field with a unique ID. In this example, the first field would be a good field to use. You could use the phone number; but it would probably be easier to use the numbers.