Discussion Locked

VB:Search/Replace of text in large files

0 helpful
19 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I have a very large text file (1 MB) that I need to search and replace pricing data. It can't be a general Search-and-Replace function, since these prices are for the specific item it is for. There is one line of product data per line, but each line is very large, so replacing the entire line would not be feasible.. also, I need to replace two prices per line. I was thinking that the easiest way is to search initially for the item name I need to change, nab that whole line, replace the values, and then input them back into the file.. but is there a better way? (Or if not, how would I go about doing the above theory?)

19 replies

by jason1

Unfortunately, no. The program is for use on machines that will not be using Excel (Or anything else aside from client software, and Windows itself).

by c1980

Would you consider opening the text file with VB code as a text ISAM database using a database recordset object . You could then search for records and replace the text field with the text you needed. You could search for and change values for fields on individual records pretty easy. You only need to identify what delimiter the records use for each field.
All of the work in getting the data and each record is handled by the ISAM driver - you only need to set the connection string. After that it is a piece of cake to find/replace/update a record in the text file.

by jason1

That sounds great, but.. as stated before.. no other software or drivers can be installed in these machines, its just Win98 and the client software. Yes, it is as much a pain as it sounds ;-)
Thank you for your response though, I will definately keep that in mind for any projects I'm not so constrained with!

by miket

If the text file is delimited, you could import the text file into a MSAccess database and use SQL to update the records necessary, then export it back to a text file. This would give you the option of having an index on your work table that would make the SQL run very quickly.

Good luck,
Mike T.

by jason1

As stated in a comment above, this program is for use on client machines that only have Windows and the company's client software on it. Thank you for your response.

by miket

Referring to my Answer #3, you don't need anything else installed on the client's machine. Just create the .mdb yourself and put it on the machine with your VB app. They don't have to have MSAccess installed for your VB application to open the MSAccess database and use it to do your work.

by c1980

Wait a minute! Are we taking the same VB language?
If you cannot even add ADO or DAO which are basic components of VB, then you will need to add something else to perform the search and replace (like VB reqular expressions). Or you are limited to aFor/Each loop if no other basic vb components can be added. Using the ISAM drivers may have confused you - this is driven by ADO/DAO. You do not even need a MDB file - you only need to create a recordset on the text file and open it like a db.

by jason1

A) Does this require I install -any- files or services to a machine for it to work (Basic Windows98 install - its bad enough I will have to install the vb6 runtime to these)

B) Will I have to change anything about the file, other that the data itself? (No adding headers, etc)

C) These are large files, each record has 200+ fields. They also have quotation marks. Will I be able to change individual fields, or does this write out each line to another file?

D) Can I get some sortof example? :)

Thanks
-Jason

by jason1

A) Does this require I install -any- files or services to a machine for it to work (Basic Windows98 install - its bad enough I will have to install the vb6 runtime to these)

B) Will I have to change anything about the file, other that the data itself? (No adding headers, etc)

C) These are large files, each record has 200+ fields. They also have quotation marks. Will I be able to change individual fields, or does this write out each line to another file?

D) Can I get some sortof example? :)

Thanks
-Jason

by johnfriz

Hi,

The search and replace idea sounds about the best one.

First off, you have said that no software or services can be *installed* on the machine. Is it permissible to copy a standalone .exe to the machine, run it, then remove the .exe again??

If the answer to this is Yes, then, because VB has good file handling and string manipulation, it would be a simple matter to write a standalone application that will do it.

There would be no need for excel, access or anything else like that (Trust me: I recently had to do a scan and extract from an 11MB file using just VB and its string manipulation functions!!!)

A couple of assumptions would be:
1) The name of the item that you want to change the prices on is known.
2) The old prices are either known (which they should be if you are modifying an existing file) or they are somehow identified in the line of product data (perhaps with a $ or ? sign)
3) The new prices are known (obviously)
4) There is a direct correlation between the old price and the new price.
i.e. if the old price is ?4.50 it is to be changed to ?4.75 in ALL cases.

Assuming that the above are true, then writing the VB application could be done in a matter of hours.

I would be happy to provide more information if you like, assuming I am on the correct track

Regards,
John

P.S. A sample line of data would be very handy.

by rrv

Forget using ISAM or mdb. VB comes handy with such problems. Check for Replace, Instr, InstrRev mid, left and right - String functions in VB. VB has samples also which would help you instead of me giving sample code or direct solution for you. Tryit for yourself. It is easy.
All the best.

This discussion is closed to new replies.