LB Booster
« search more than 2 items »

Welcome Guest. Please Login or Register.
Apr 1st, 2018, 04:20am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
We apologize Conforums does not have any export functions to migrate data.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
LB Booster Resources
LB Booster documentation
LB Booster Home Page
LB Booster technical Wiki
Just BASIC forum
BBC BASIC Home Page
Liberty BASIC forum (the original)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: search more than 2 items  (Read 363 times)
hammerjit
New Member
Image


member is offline

Avatar




PM


Posts: 26
xx search more than 2 items
« Thread started on: Jul 23rd, 2015, 09:03am »

Hi....I am having problem with this combining 3 conditions

I want to search my data file for '180822' and lines without "CF".
But I cant get it to work.

This is my sample data
CF,2015,180821,5,24
CF,2015,180822,2,21
CF,2015,180823,7,24
CF,2015,180824,1,16
1,2015,180821,24-07-15,1
1,2015,180822,24-07-15,1
1,2015,180803,15-07-15,1
4,2015,180804,20-07-2015,1
1,2015,180822,25-05-15,0.5


This is my code
Code:
open "test.txt" for input as #fo
search1$="180822"
c=0
line input #fo,l$
while eof(#fo)=0 or (trim$(word$(l$,3,","))=search1$ and word$(l$,1,",")<>"CF")
c=c+1

input #fo, q$
test1$(c)=q$
input #fo, q$
test2$(c)=q$
input #fo, q$
test3$(c)=q$
input #fo, q$
test4$(c)=q$
input #fo, q$
test5$(c)=q$
end if
wend
close #fo
recnum=c

showRec1$=""
showRec2$=""

for i=1 to recnum
showRec1$=showRec1$+test4$(i)+chr$(13)+chr$(10)
showRec2$=showRec2$+test5$(i)+chr$(13)+chr$(10)
next i

print showRec1$
print showRec2$

 
User IP Logged

Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 1348
xx Re: search more than 2 items
« Reply #1 on: Jul 23rd, 2015, 10:38am »

on Jul 23rd, 2015, 09:03am, hammerjit wrote:
I want to search my data file for '180822' and lines without "CF".

If the extract from your data file is typical, it seems that you don't actually need to test the individual fields separately because - apparently - '180822' can only occur in the 3rd field and 'CF' only in the 1st field. In that case you can check the entire line in one go using INSTR:

Code:
    open "test.txt" for input as #fo
    while not(eof(#fo))
      line input #fo, l$
      if instr(l$, "180822") <> 0 and instr(l$, "CF") = 0 then
        print l$
      end if
    wend
    close #fo
    end 

But if it's important to check the specific fields then this works:

Code:
    open "test.txt" for input as #fo
    while not(eof(#fo))
      line input #fo, l$
      if word$(l$, 3, ",") = "180822" and word$(l$, 1, ",") <> "CF" then
        print l$
      end if
    wend
    close #fo
    end 

I've not bothered to store the results in an array for later use, but if you need that it is obviously simple to add:

Code:
    open "test.txt" for input as #fo
    c = 0
    while not(eof(#fo))
      line input #fo, l$
      if word$(l$, 3, ",") = "180822" and word$(l$, 1, ",") <> "CF" then
        c = c + 1
        test$(c) = l$
      end if
    wend
    close #fo
    recnum = c

    showRec1$ = ""
    showRec2$ = ""

    for i = 1 to recnum
      showRec1$ = showRec1$ + word$(test$(i), 4, ",") + chr$(13) + chr$(10)
      showRec2$ = showRec2$ + word$(test$(i), 5, ",") + chr$(13) + chr$(10)
    next i

    print showRec1$
    print showRec2$ 
User IP Logged

hammerjit
New Member
Image


member is offline

Avatar




PM


Posts: 26
xx Re: search more than 2 items
« Reply #2 on: Jul 27th, 2015, 02:42am »

Thanks Richard...that helped me a lot.
User IP Logged

hammerjit
New Member
Image


member is offline

Avatar




PM


Posts: 26
xx Re: search more than 2 items
« Reply #3 on: Jul 27th, 2015, 08:57am »

Richard, just to add to this code...if I want to output but after sorting the date field(4 field) how can I go about that?

eg. the above code will output
180822 24-07-15
180822 25-05-15

But it should be sorted by May then July.


CF,2015,180821,5,24
CF,2015,180822,2,21
CF,2015,180823,7,24
CF,2015,180824,1,16
1,2015,180821,24-07-15,1
1,2015,180822,24-07-15,1
1,2015,180803,15-07-15,1
4,2015,180804,20-07-2015,1
1,2015,180822,25-05-15,0.5

Code:
open "test.txt" for input as #fo
    c = 0
    while not(eof(#fo))
      line input #fo, l$
      if word$(l$, 3, ",") = "180822" and word$(l$, 1, ",") <> "CF" then
        c = c + 1
        test$(c) = l$
      end if
    wend
    close #fo
    recnum = c

    showRec1$ = ""
    showRec2$ = ""

    for i = 1 to recnum
      showRec1$ = showRec1$ + word$(test$(i), 4, ",") + chr$(13) + chr$(10)
      showRec2$ = showRec2$ + word$(test$(i), 5, ",") + chr$(13) + chr$(10)
    next i

    print showRec1$
    print showRec2$ 
 
« Last Edit: Jul 28th, 2015, 12:41am by hammerjit » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls