Subject Re: Grid search
From Akshat Kapoor <akshat.kapoor@kapoorsons.in>
Date Fri, 25 Sep 2020 12:50:29 +0530
Newsgroups dbase.getting-started

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