Problem importing text file and searching for strings 
Author Message
 Problem importing text file and searching for strings

I'm new to Access 97 and VBA but I've researched on newsgroups enough to
almost figure out how to do this. The database I'm making will be
importing 100-150k text files and I need to be able to read the
following [variable names changed as to recognize the upcoming NFL
season] :)

Beginning of File
100 lines of junk....varies from file to file
...
TeamList =!    ( Note: This is unique in the file! )
Team =!
Name = "Team_1";
TeamName = "Packers";
TeamStrength = 9;
Color = "yellow"
Team ={
Name = "Team_2";
TeamName = "Cowboys";
TeamStrength = 5;
Color = "white";
...
20 lines of junk....varies from file to file
...
PlayerList =!  ( Note: This is unique in the file! )
Player =!
Name = "Emmit Smith";
PlayerNumber = 22;
PlayerPosition = "RB";
TeamName = "Team_2";
Player =!
Name = "Reggie White";
PlayerNumber = 92;
PlayerPosition = "DL";
TeamName = "Team_1";
Player =!
Name = "Troy Aikman";
PlayerNumber = 8;
PlayerPosition = "QB";
TeamName = "Team_2";
....
This goes on and on for all players in no particular order.
...
200-300 lines of junk...varies from file to file
End of File

Nothing tells me how many players there are total or how many on each
team. The number of teams in each file can vary too, from 1 to maybe 3
or 4. The final list will be a list of players sorted by number.

Where I stand so far is I can import this file using TransferText into
two columns into a table.  I could now do a record search and pick out
the data I need.  I can also do a line by line Input and until I get to
the strings Teamlist and PlayerList and then get what I need, which
seems easier.

Two things I need advice on:

1.  First is will it take a long time to Input a file line by line as
opposed to Transfertext?  It takes no time at all with the TransferText
but I still need to sort through all the records which might take time.  

2.  Second is how the heck to do the string searches :)  I've seen some
examples on this in the groups but maybe someone could help me on how to
do a simple string search and separate the variables by the "=" sign on
my lines and get rid of the ";" at the end of my lines.

I have to work with the file "as is" and I have many many files I'll
have to import. Any advice on these two things is definitely
appreciated.

murph  



Tue, 13 Feb 2001 03:00:00 GMT  
 Problem importing text file and searching for strings
Q1)  In other environs, I've read so many text files in using C level;
FOPEN(), FGETS(), etc commandd to read line by line, extract data, and
insert into a table its firmly engrained in the brain.  And it's fast.  A
600 page report would take less than a minute to do the task.  Don't know if
Access would be as fast but it should be acceptable.

Q2  Try this in debug.
strvar = "variable = Murph"
strname = right(strvar,len(strVar) - instr(strvar,"=") - 1)

This proc subtracts the length of the string from the postion of the = sign
and subtracts 1 to remove the leading space.  I could have done a trim
instead of -1 instead.

I probably would read line by line.  If the line has an = sign, I'd get the
left and right of the statement and then assign to a field.

Set rst = ..OpenRecordset...
FieldToUpdate = left(strvar,instr(strvar,"=")-1)
FieldValueIs = right(strvar,len(strVar) - instr(strvar,"=") - 1)
With rst
    .AddNew
    Select Case FieldToUpdate
    Case Team
        .TeamField = FieldValueIs
    ...
    End Select
    .Update
EndWith

You don't want to addnew/update for each line.  Anytime you see Player,
addnew and anytime you see teamname then update.

Quote:
> Two things I need advice on:

> 1.  First is will it take a long time to Input a file line by line as
> opposed to Transfertext?  It takes no time at all with the TransferText
> but I still need to sort through all the records which might take time.

> 2.  Second is how the heck to do the string searches :)  I've seen some
> examples on this in the groups but maybe someone could help me on how to
> do a simple string search and separate the variables by the "=" sign on
> my lines and get rid of the ";" at the end of my lines.



Mon, 26 Feb 2001 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Search for a text string in text file

2. Working with Text Files - Searching for strings and then exporting to new file

3. Importing and Searching 800kb text file

4. Search for and Replace strings in a text file

5. Function to search text file for given string

6. Slow Searching Text File / String

7. SEARCHING A TEXT FILE FOR A STRING

8. Searching And Replacing Strings Within A Text File

9. search a string in text file

10. Searching And Replacing Strings Within A Text File

11. Problem importing a text file to a linked table in Access 2000

12. Problem Importing Text File into Recordset

 

 
Powered by phpBB® Forum Software