help for a search function

Post Reply
User avatar
Silvio.Falconi
Posts: 7119
Joined: Thu Oct 18, 2012 7:17 pm

help for a search function

Post by Silvio.Falconi »

I wish before to save a data search on the same database if the data passed is the same or not

when it search a classroom sample 1A

and control if the nday_hour sample "11"

is the same
and if it found it must return .f. ( no free)


but perhaps there is an error and the function not run ok



Code: Select all | Expand


#include "FiveWin.ch"

REQUEST DBFCDX
REQUEST DBFFPT
EXTERNAL ORDKEYNO,ORDKEYCOUNT,ORDCREATE,ORDKEYGOTO



Function test()

local nGiornoOra := "11"

USE ORARIO ALIAS OR
INDEX ON str(PROF,3) TAG ORARIO1

  Do while ! or->(eof())

      If classelibera(nGiornoOra)
       replace  or->gg_ora with nGiornoOra
      Endif

      or->(dbskip())

   enddo
return nil



function ClasseLibera(GiornoOra)
    Local lRet
    local cClasse:= alltrim(or->classe)
    Local nRecord:= or->(RecNo())



    SELECT OR
    INDEX ON  UPPER(or->classe)  tag CLASSE TO ORA

     or->(dbGoTop())

     If dbseek(cClasse,.T.)
       If or->GG_ORA==GiornoOra
          lRet:= .f.
       else
          lRet:= .t.
       endif
    else
       lRet:= .t.
    Endif

    or->(dbSetOrder(1))
   or->(dbGoto(nRecord))

return lret





 




the strcture of dbf used

dbcreate('ORario',;
{{"prof ", "n", 3, 0},;
{"classe ", "c", 4, 0},;
{"aula ", "c", 4, 0},;
{"materia ", "n", 3, 0},;
{"flag ", "c", 1, 0},;
{"gruppo ", "n", 3, 0},;
{"oreseq ", "c", 1, 0},;
{"gg_ora ", "c", 2, 0}, ;
{"num ", "c", 10, 0}, ;
{"blocco ", "c", 1, 0}}, 'DBFCDX' )
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
mercurial
Posts: 16
Joined: Wed Feb 04, 2015 2:26 pm

Re: help for a search function

Post by mercurial »

I added comments in the code

Silvio.Falconi wrote:

Code: Select all | Expand


...

function ClasseLibera(GiornoOra)
    Local lRet
    local cClasse:= alltrim(or->classe)
    Local nRecord:= or->(RecNo())

    SELECT OR
// You create a new index every time the function is called !!!!
    INDEX ON  UPPER(or->classe)  tag CLASSE TO ORA

     or->(dbGoTop())
// You specify .T., this means that the seek can point to a record NOT OF THAT CLASSE!
// You don't loop on all records of that CLASSE to look for or->GG_ORA==GiornoOra
     If dbseek(cClasse,.T.)
       If or->GG_ORA==GiornoOra
 ...
 



I'd use a LOCATE as per my message I sent as reply in other threads.
User avatar
Silvio.Falconi
Posts: 7119
Joined: Thu Oct 18, 2012 7:17 pm

Re: help for a search function

Post by Silvio.Falconi »

Mercurial,
I use cdx I think I cannot use locate

How you 'll make this function
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
mercurial
Posts: 16
Joined: Wed Feb 04, 2015 2:26 pm

Re: help for a search function

Post by mercurial »

You can use LOCATE FOR with any DBF... if there is an active index, the search is done using the sequence of the index, otherwise SET ORDER TO 0 and you will get the records in their natural order (recno())

Before writing the function, please specify better what you need to do because it is not really clear.
For example, you have
mCLASSE := "1A"
mGG_ORA := "11"
What do you want to know?
LOCATE FOR CLASSE=mClasse .and. GG_ORA == mGG_ORA
and then if found() == .T. means the data is already in the database (so the class is not free....)

You can still use an index if you want, but then create the index on CLASSE+GG_ORA then do a dbSeek WITHOUT .T.
But move away the dbCreateIndex from the function, it should be before the loop.
BTW: from your other post, it seems you already have such index!... INDEX ON (upper(CLASSE)+upper(GG_ORA))
User avatar
Silvio.Falconi
Posts: 7119
Joined: Thu Oct 18, 2012 7:17 pm

Re: help for a search function

Post by Silvio.Falconi »

sorry, the old clipper function is this

Code: Select all | Expand

static function CLASSELIB(nOre, ngiorno, nOra)
   local cClasse:= orario->classe     ,;
          nRecord:= orario->(RecNo()), ;
          n:= 1
   orario->(dbSetOrder(3))
   for n= 0 to nOre - 1
      if (orario->(dbSeek(cClasse + Str(ngiorno, 1) + iif(nOra + n ;
            == 10, "0", Str(nOra + n, 1)))))
         orario->(dbSetOrder(8))
         orario->(dbGoto(nRecord))
         return .F.
      endif
   next
   orario->(dbSetOrder(8))
   orario->(dbGoto(nRecord))
   return .T.



why I must change it ?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
mercurial
Posts: 16
Joined: Wed Feb 04, 2015 2:26 pm

Re: help for a search function

Post by mercurial »

Silvio.Falconi wrote:sorry, the old clipper function is this

Code: Select all | Expand

static function CLASSELIB(nOre, ngiorno, nOra)
...
 


why I must change it ?


Sorry Silvio, I don't understand what you want to say.

ClasseLibera and CLASSELIB are DIFFERENT and they do DIFFERENT things, and produce DIFFERENT results.

For example, in CLASSELIB dbSeek hasn't the second parameter set to .T. !!! As written now, ClasseLibera has no... how to say, it has no logic... results are just random... also if you remove the .T. results will still be not what you were looking for.

I don't know if this forum allows to send PM, or we can move to the italian forum so that we may circumvent the language barrier.
User avatar
Silvio.Falconi
Posts: 7119
Joined: Thu Oct 18, 2012 7:17 pm

Re: help for a search function

Post by Silvio.Falconi »

ok I stay on Italian forum
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)
I use : FiveWin for Harbour November 2023 - January 2024 - Harbour 3.2.0dev (harbour_bcc770_32_20240309) - Bcc7.70 - xMate ver. 1.15.3 - PellesC - mail: silvio[dot]falconi[at]gmail[dot]com
Post Reply