FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Problem of a function
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM

Problem of a function

Posted: Mon Feb 02, 2015 04:51 PM
the function
Code (fw): Select all Collapse
function CLASSELIB(nOreClasse, nGiorno, nOra)

   local nClasse:= or->classe
   local nRecord:= or->(RecNo())
   local n:= 1

   or->(dbSetOrder(3))
   for n:= 0 to nOreClasse - 1
      if (or->(dbSeek(nClasse + Str(nGiorno, 1) + iif(nOra + n ;
            == 10, "0", Str(nOra + n, 1)))))
         or->(dbSetOrder(1))
         or->(dbGoto(nRecord))
         return .F.
      endif
   next
   or->(dbSetOrder(1))
   or->(dbGoto(nRecord))
   return .T.


the function should look in the archive from the beginning if the class corresponds to the class passed. If the date entered in field GG_Ora equals the day-time passed, the function should return a false value otherwise a true value

The index of the archive schedule is set on the third, and that is INDEX ON (upper(CLASSE)+upper(GG_ORA)) TAG ORARIO3

The parameter passed nOreClasse is a number corresponding to the difference in how many hours a class must be committed unless the value of the field ore_as

I use this function in a loop "For Next" which is inside a loop "DoWhile" wich is inside to another cicle "forNext"

for nGiro:= 1 to 10
SELECT OR
OR->(dbSetOrder(2))
OR->(dbGoTop())

while (!OR->(EOF()))

nlezione := OR->(RECNO())

if (Empty(OR->gg_ora) .AND. OR->classe != "1DISP" )

SELECT DO
DO->(dbGoto(OR->prof))


SELECT MA
MA->(dbGoto(OR->materia))


SELECT AU
AU->(dbSeek(OR->aula))


SELECT CL
CL->(dbSeek(OR->classe))
nOreClasse := CL->MAX_ORE-CL->ORE_ASS


SELECT GR
GR->(dbGoto(OR->gruppo))


For nGiorno = 1 to 6 // days of Week at school
for nOre = 1 to 6 // hours
nGG_Ora:= str(nGiorno,1)+str(nOra,1)
IF GiornoLib(nGiorno, @nOre, nOra)
exit
exit
Endif


IF CLASSELIB(nOreClasse, nGiorno, nOre)
cl->ore_ass+=1
or->gg_ora:= nGG_Ora
Endif

next
next
When on the database there is one record he function can run good
but when there are many records as in this case

and the function not run good

Ho I can resolve ?

I have to explain that a teacher can not 'exist in a class and also in another class at the same time of day past:

teacher 1
monday 1
time 1
classroom 1A


for example if teacher_1 the day Monday at the first hour is in 1A can not' be inserted in 2B at the same time Monday

How can I fix?
Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 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
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM

Re: Problem of a function

Posted: Tue Feb 03, 2015 04:20 PM
Silvio,

I have modified your routine to be a little more clear. In order for us to test it we need the database file containing sample data, and several sample sets of test data with the correct answers.

James

Code (fw): Select all Collapse
/* Function should look in the database to see
if the class corresponds to a class passed. 

If the date in field GG_Ora equals the day-time passed, 
the function should return false, otherwise true.
*/

Function CLASSELIB(nOreClasse, nGiorno, nOra)

   local nClasse:= or->classe
   local nRecord:= or->(RecNo())
   local nOrder:= or->(indexOrder())
   local n:= 1
   local lReply:=.t.

   or->(dbSetOrder(3))
   for n:= 0 to nOreClasse - 1
      if (or->(dbSeek(nClasse + Str(nGiorno, 1) + iif(nOra + n ;
            == 10, "0", Str(nOra + n, 1)))))
         lReply .F.
         Exit
      endif
   next

   or->(dbsetOrder( nOrder ))
   or->(dbGoto( nRecord ))
   
Return lReply

// EOF
FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10
Posts: 7318
Joined: Thu Oct 18, 2012 07:17 PM

Re: Problem of a function

Posted: Wed Feb 04, 2015 12:43 PM

I sent you some databases ( sample data)

Now I need to control if a classroom is on the same hour as I wrote you

Since from 1991/1992 ( fw for clipper Rel. 14.4 - Momos)

I use : FiveWin for Harbour March-April 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
Posts: 16
Joined: Wed Feb 04, 2015 02:26 PM

Re: Problem of a function

Posted: Wed Feb 04, 2015 08:14 PM
Hi Silvio,
I think there is something I don't understand.

In another post you sent 2 GIORNOLIB functions, similar but working on different databases.

I think that the function is wrong...
Code (fw): Select all Collapse
STATIC FUNCTION GIORNOLIB( ngiorno, nOre, nOra )

   IF ( Val( anagrafe->giornoli ) == ngiorno 
  .AND. nOra == 1 ;
  .AND. anagrafe->punti < "3"
  .AND. Val( anagrafe->giornoli ) == ngiorno ;
  .AND. nOra == 2
  .AND. anagrafe->punti < "2" )
      nOre := iif( Left( datis->parame, 1 ) == "0", 10, Val( Left( datis->parame, 1 ) ) )
      RETURN .F.
   ENDIF

   RETURN .T.


As you can see all the expressions in the IF are in .AND. and nOra == 1 .AND. nOra == 2 is, of course, ALWAYS .F. !

I think this code is for the "desiderata" (wishes) of the teachers... but why do you check is nGiorno is == "giornoli(bero?)" (it is a day with no teaching in class) .AND. other conditions? If it is "giorno libero" they are not supposed to be at school...

And of course, there are 2 groups of conditions that should be connected by an .OR.

So, if the code you posted is this, and my fever didn't cluttered my head, this function always returns .T.


This means that in this code ClasseLib() is never reached...
Code (fw): Select all Collapse
   FOR nGiorno = 1 TO 6 // days of Week at school
      FOR nOre = 1 TO 6 // hours
         nGG_Ora := Str( nGiorno, 1 ) + Str( nOra, 1 )
         IF GiornoLib( nGiorno, @nOre, nOra )  // ALWAYS .T.
            EXIT   // ALWAYS EXECUTED
            EXIT   // WHY 2 EXITs????
         ENDIF

         IF CLASSELIB( nOreClasse, nGiorno, nOre )  // NEVER EXECUTED...
            cl->ore_ass += 1
            or->gg_ora := nGG_Ora
         ENDIF

      NEXT
   NEXT


Last, I did not understand what you say here:

I have to explain that a teacher can not 'exist in a class and also in another class at the same time of day past:
....
for example if teacher_1 the day Monday at the first hour is in 1A can not' be inserted in 2B at the same time Monday

Why do you say "at the same time of day PAST" ? What do you mean with that PAST? because the example says that one teacher can't be in two places at the same time, but that "past" may change the meaning...
If "past" is here and shouldn't be, and you only want to check that a teacher is not assigned more than one class for each teaching hour, just do a LOCATE:
Code (fw): Select all Collapse
mGG_ORA = "11" // monday, first hour
mClasse = "1A"
mProf = 25
LOCATE FOR PROF == 25 // teacher id 25
   .AND.GG_ORA == mGG_ORA 
   .AND. Classe != mClasse

If a record is found, it means that the teacher is assigned another class on Monday, first hour.

You can use dbSeek of course, but I don't know the available indexes, and indexOrder( 3 ) can't be used since it is based on Classe + Giorno + Ora... Better set dbSetOrder(0) and use a LOCATE.... in the biggest italian schools you shoud have a maximum of about 2000 records in that DBF....

Continue the discussion