Liberty BASIC Community Forum
« ListboxSearch »

Welcome Guest. Please Login or Register.
Nov 24th, 2017, 10:49am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: ListboxSearch  (Read 171 times)
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx ListboxSearch
« Thread started on: Aug 19th, 2017, 09:05am »

Can anyone with a sharper eye than me see why this sometimes does not select a listed item? Key c into the textbox, change its contents if you wish then select an item in the listbox below. Sometimes it does not select the item?


Code:
    'This program prefills a listbox with items matching search criteria
    'nomainwin

    dim array$(10)
    array$(1)="apple"
    array$(2)="car"
    array$(3)="cat"
    array$(4)="cement"
    array$(5)="dog"
    array$(6)="pavement"
    items=6

    WindowWidth = 500
    WindowHeight = 400
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    statictext #main.search, "Enter your search", 80, 20, 244, 20
    textbox #main.textbox, 80, 40, 300, 20
    listbox #main.listbox, temparray$(), [update],80, 65, 300, 200
    open "User Input" for window as #main
    #main "trapclose [quit]"
    #main.textbox "!setfocus"
    #main.listbox "singleclickselect"

    timer 250, [search]
    wait


[search]
    timer 0
    #main.textbox "!contents? text$"
    dim temparray$(items)
    found=1
    for n= 1 to items
        if instr(array$(n),text$,1)>0 then temparray$(found)=array$(n) :found=found+1
    next
    #main.listbox "reload"
    #main.listbox "selectindex ";0
    timer 250, [search]
    wait

[update]
    timer 0
    #main.listbox "selection? choice$"
    print choice$
    redim temparray$(items)
    #main.listbox "reload"
    #main.textbox ""
    #main.textbox "!setfocus"
    timer 250, [search]
    wait


[quit]
    close #main
    end


 
User IP Logged

MKnarr
Senior Member
ImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 431
xx Re: ListboxSearch
« Reply #1 on: Aug 19th, 2017, 4:36pm »

Rod, I could not make it fail but I did make three minor changes. I remarked two lines and added the set focus line to the search section. I'm not sure what found is for because in you example it isn't used.

Code:
'This program prefills a listbox with items matching search criteria
    'nomainwin

    dim array$(10)
    array$(1)="apple"
    array$(2)="car"
    array$(3)="cat"
    array$(4)="cement"
    array$(5)="dog"
    array$(6)="pavement"
    items=6

    WindowWidth = 500
    WindowHeight = 400
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    statictext #main.search, "Enter your search", 80, 20, 244, 20
    textbox #main.textbox, 80, 40, 300, 20
    listbox #main.listbox, temparray$(), [update],80, 65, 300, 200
    open "User Input" for window as #main
    #main "trapclose [quit]"
    '#main.textbox "!setfocus"
    #main.listbox "singleclickselect"

    timer 250, [search]
    wait


[search]
#main.textbox "!setfocus"
    timer 0
    #main.textbox "!contents? text$"
    dim temparray$(items)
    found=1
    for n= 1 to items
        if instr(array$(n),text$,1)>0 then temparray$(found)=array$(n) :found=found+1
    next
    #main.listbox "reload"
    #main.listbox "selectindex ";0
    timer 250, [search]
    wait

[update]
    timer 0
    #main.listbox "selection? choice$"
    print choice$
    redim temparray$(items)
    #main.listbox "reload"
    #main.textbox ""
    '#main.textbox "!setfocus"
    timer 250, [search]
    wait


[quit]
    close #main
    end
 
User IP Logged

G. Rahman
Guru
ImageImageImageImageImage


member is offline

Avatar




Homepage PM

Gender: Male
Posts: 1146
xx Re: ListboxSearch
« Reply #2 on: Aug 19th, 2017, 6:18pm »



hmmm strange .....

in the example of Mknarr
change the timer in the search loop to 550 and
the program works ....

Gordon
User IP Logged

Gordon Rahman

http://www.libertybasic.nl
Rod
Global Moderator
ImageImageImageImageImage


member is offline

Avatar

Graphics = goosebumps!


PM

Gender: Male
Posts: 5567
xx Re: ListboxSearch
« Reply #3 on: Aug 20th, 2017, 04:01am »

Ok, thanks everyone. I gave up on the timer, it seems more stable just with a button to move focus.

Code:
    'This program prefills a listbox with items matching search criteria
    nomainwin

    dim array$(10)
    array$(1)="apple"
    array$(2)="car"
    array$(3)="cat"
    array$(4)="cement"
    array$(5)="dog"
    array$(6)="pavement"
    items=6

    WindowWidth = 400
    WindowHeight = 300
    UpperLeftX=int((DisplayWidth-WindowWidth)/2)
    UpperLeftY=int((DisplayHeight-WindowHeight)/2)
    statictext #main.search, "Enter your search", 20, 10, 150, 25
    textbox #main.textbox, 20, 40, 200, 25
    button #main.search, "  Search  ", [search], UL, 230, 40
    listbox #main.listbox, temparray$(), [update],20, 70, 300, 150
    textbox #main.selected, 20,230,300,25
    open "User Input" for window as #main
    #main "trapclose [quit]"
    #main.listbox "singleclickselect"
    #main.textbox "!setfocus"
    wait

[search]

    #main.textbox "!contents? text$"
    dim temparray$(items)
    index=1
    for n= 1 to items
        if instr(array$(n),text$,1)>0 then temparray$(index)=array$(n) :index=index+1
    next
    #main.listbox "reload"
    #main.listbox "selectindex ";0
    wait

[update]
    #main.listbox "selection? choice$"
    #main.selected choice$
    wait


[quit]
    close #main
    end

 
User IP Logged

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

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls