Jump to content

handling text file and search a string using VB

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
pbosek

pbosek

    Newbie

  • Members
  • Pip
  • 1 posts
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

#2
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,722 posts
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"


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