Re: Advice: Reading records from text file

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

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


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



Relevant Pages

  • Re: Advice: Reading records from text file
    ... "Robert" wrote in ... Dim txtLine as String ... str = "Test Search" ... If you needed the data more you could load it into an array once and then ...
    (microsoft.public.vb.general.discussion)
  • Re: _ecvt, _gcvt and _fcvt problem
    ... The question is...Do you understand what Robert ... >>>But I have problem about conversion double to string. ... >> problem I strongly recommend taking some time to learn about UNICODE. ... >> please indicate which newsgroup and message). ...
    (microsoft.public.windowsce.embedded.vc)
  • Re: User Define Array Data Type - Subscript out of range
    ... Works just DANDY, Robert! ... strDataType As String ... ' Load Array ...
    (microsoft.public.access.modulesdaovba)
  • Re: String.each
    ... On 3/3/07, Robert Klemme wrote: ... >>> each character of a string and then processes it using a block. ... String's enumeration is a bit weird and inconsistent. ... String as array of lines does have it's uses at times but I wonder ...
    (comp.lang.ruby)
  • Re: Improving Adas image - Was: 7E7 Flight Controls Electronics
    ... Robert I. Eachus wrote: ... function Imagereturn String is ... type Color is (Red, Orange, Yellow, Blue, Green, Violet, ...
    (comp.lang.ada)