Re: Advice: Reading records from text file
From: DS (t.h.i.s.n.t.h.a.t_at_a.d.e.l.p.h.i.a..n.e.t)
Date: 02/14/04
- Next message: Rick Rothstein: "Re: Advice: Reading records from text file"
- Previous message: DavidM: "Data Grid and Form Size"
- In reply to: Robert: "Advice: Reading records from text file"
- Next in thread: Rick Rothstein: "Re: Advice: Reading records from text file"
- Messages sorted by: [ date ] [ thread ]
Date: 14 Feb 2004 16:26:14 -0600
"Robert" <nomail@nomail.com> wrote in
news:2BuXb.545613$_x2.1213188@zonnet-reader-1:
> Hi,
>
> For my application i have a file (4 Kb) with two fields and 170
> records (text file = tab separated file)
> What is the fastest way to read this file and find a specific record?
>
> Now it's a separate file, can I create a resource file from this file
> with the same functionality?
>
> Thx,
>
> Robert
>
>
Robert,
For the most simplistic way, and taking into account that the text file
is as follows:
fld1<TAB>fld2
fld1<TAB>fld2
and not:
rec1-1<TAB>rec1-2<TAB>rec2-1<TAB>rec2-2<TAB>....
You could just use the OPEN statement and run thru the lines
sequentially...
Dim txtLine as String
Dim str as String
str = "Test Search"
OPEN "path/filename.ext" FOR INPUT As #1
DO Until EOF(1)
INPUT #1, txtLine
If Ucase(left$(txtLine,len(str))) = ucase(str) THEN
//At this point txtLine is filled with the entire line that//
//starts with your criteria//
//then do whatever you need to do with it//
endif
LOOP
CLOSE #1
I'm using UCase above to make the conditional case independant. And
assuming that the first 'field' is what you are searching on. Use INSTR
in the comparison to find the info anywhere in the string.
If you needed the data more you could load it into an array once and then
use and manipulate the array, since it's a very small file.
Regards,
DS
- Next message: Rick Rothstein: "Re: Advice: Reading records from text file"
- Previous message: DavidM: "Data Grid and Form Size"
- In reply to: Robert: "Advice: Reading records from text file"
- Next in thread: Rick Rothstein: "Re: Advice: Reading records from text file"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|