Hi,
I have text file with tab delimited values(like hh \t mm \t ss \tt ecode \t user \t name \t machinenum \t state and so on) arranged in a row and column representation( ~ 80 columns). My task has to search for a state(string) in the file and get the corresponding values from that row. I used to handle this by importing into excel using VBA Querytables, then search for the string in excel thereby getting the required values from various columns of the same row. But since the input text files are on the size 1Mb<SIZE<3.5Mb, importing to excel itself is taking around 2min which has become a performance issue. Is there anyway to speed it up or otherwise open the textfile , search and then get values? The text file can be opened in MS word but each line(1 row x 80 columns) of notepad gets splitted across 6 lines which makes it difficult for me to search. Can anyone let me know an alternate approach?
Do you think working it out with random access file approach, read every line and search for string will also be performance issue for size>1Mb?
Hope i have done my part of homework before posting this long message.
thanks in advance
handling text file and search a string using VB
Started by pbosek, Feb 06 2008 03:18 AM
1 reply to this topic
#1
Posted 06 February 2008 - 03:18 AM
|
|
|
#2
Posted 25 February 2008 - 07:49 PM
Search through the entire file for the desired string, then back up until you hit CRLF, which marks the end of the previous line. Then read in the entire line that follows.
Search for "MyText"
Search for "MyText"
STEP 1: Find string mytext mytext mytext mytext mytext mytext mytext mytext MyText mytext ^found string STEP 2: Back up to previous CRLF mytext mytext mytext mytext mytext ^found previous CRLF mytext mytext mytext MyText mytext STEP 3: Move forward one character to beginning of desired row mytext mytext mytext mytext mytext mytext mytext mytext MyText mytext ^beginning of desired row STEP 4: Read mytext mytext mytext mytext mytext mytext mytext mytext MyText mytext |<------------------------------->| read in data STEP 5: Parse data


Sign In
Create Account

Back to top









