Subject Re: Grid search
From Robbie Nott <robnott@mweb.co.za>
Date Fri, 25 Sep 2020 13:45:09 +0200
Newsgroups dbase.getting-started

On 9/25/2020 9:20 AM, Akshat Kapoor wrote:
> On 24.09.2020 21:35, Robbie Nott wrote:
>> Hi dBase
>>
>> Am wanting to do a search ( like the SeekerSQL ) but from a Grid.
>>
>> User wants to set focus on the grid and then type in a few characters
>> to do a progressive search.
>>
>> Thinking about the on_Key() but need to store the previous characters
>> so that the progressive search works properly.
>>
>> Also thinking about some kind of time factor where the process would
>> "forget" what was typed in after a few seconds...
>>
>> Any assistance greatly appreciated ( including maybe an RTFM )
>
> Good Afternoon Robbie,
> I am pasting code that I am using to search through all columns of the
> grid. It is designed for onClick Event.
>
> Please adopt according to your own needs
>     function SEARCH_onClick()
> //      msgbox("To search for " + form.search_txt.value)
> //      form.rowset.first()
>        local mfound , curr_row,search_txt
>        search_txt = upper(alltrim(form.search_txt.value))
>        curr_row = form.rowset.fields["recno"].value
>        mfound = false
>        do while not form.rowset.endofset
>           for n = 2 to form.rowset.fields.size
>              if not empty(form.rowset.fields[n].value)
>                 do case
>                    case form.rowset.fields[n].type $ "IntegerNumeric" //
> or "N"
>                       if search_txt $ str(form.rowset.fields[n].value,16,2)
>                          mfound = true
>                       endif
>                    case "Char" $ form.rowset.fields[n].type    // for
> float / numerical
>                       if search_txt $ upper(form.rowset.fields[n].value)
>                          mfound = true
>                       endif
>                    case form.rowset.fields[n].type = "DBDate"   // or "N"
>                       if search_txt $ dtoc(form.rowset.fields[n].value)
>                          mfound = true
>                       endif
>                 endcase
>              endif
>           next
>           if mfound
>              exit
>           else
>              form.rowset.next()
>           endif
>        enddo
>        if not mfound
>           msgbox("Sorry the text was not found")
>           form.rowset.applylocate("recno ="+curr_row)
>        else
>           msgbox("Text found ")
>        endif
>        return
>
>
> Watch for word wrap at places.
>
> I hope this helps.
> Regards
> Akshat

Hi Akshat

Many thanks for your sample code.
Super useful that it searches all the columns.
I will certainly put it to good use in my programs.

Now I just need to figure out how to catch the keys typed when the grid
has focus.
Thinking of a form variable to accumulate the keys typed within a short
period of time. This would get wiped after a certain pause.
Accumulate keys and perform a search after a pause.

Thing is, dBase can't cancel a running search when a new key sequence is
typed - mmm

Perhaps this is the point when I drop this line of exploration.
Thinking I would need to create a Thread that could be terminated at will.

SeekerSQL it is...

Appreciate your interest and feedback
Your code is a delight to read

Regards
Robbie