Simple task-not simple for Dummy, Help 
Author Message
 Simple task-not simple for Dummy, Help

I have a routine written within the embedded code.  The routine is to open a
file read the data based on a relationship with another file, process a loop to
caluculate  an average, but only use the lastest (by date) records.  The key I
am setting is a multi field key the contains a reference number, date, and
score (the item to be averaged).  However, the program does not calculate
correctly.  It takes the best of 5 of all scores, not best of 5 from only ten
scores. Here is the code, any help is soooooooooooooooo greatly appreciated:

FindAverage         routine

  SET(PLA:KeyMemberNumber)
  LOOP until Access:Players.Next()
    clear(Rou:Record)
    ROU:MemberNumber = PLA:MemberNumber
    Counter# = 0
    Tally$ = ''
    count = 1
    SET(ROU:RoundsKey, ROU:RoundsKey)
    Loop until Access:Rounds.Next()
      If Rou:MemberNumber <> PLA:MemberNumber or (Count > 10) then break.
      My:Score = ROU:PointsMade
      My:date = ROU:Date
      Add(ScoreQ)
      Counter# += 1
      count += 1
    END ! loop rounds
    If Counter#
      SORT(ScoreQ,-My:Score,-my:date)
      case Counter#
        of 1 to 2
          EndScores# = 1
        of 3 to 4
          EndScores# = 2
        of 5 to 6
          EndScores# = 3
        of 7 to 8
          EndScores# = 4
        else
          EndScores# = 5
      END ! case
      LOOP J# = 1 TO EndScores#
        GET(ScoreQ,j#)
        Tally$ += My:Score
    END         ! j loop
      PLA:AveragePoints = Tally$ / EndScores#
    END           !if counter
    IF PLA:AVERAGEPOINTS < 15
       PLA:AVERAGEPOINTS = 15
    END           ! if under 15
    Access:Players.Update()
    FREE(ScoreQ)
  END             ! main loop
 POST(Event:CloseWindow)

 exit
!
--------------------------------------------------------------------------
----------



Fri, 08 Dec 2000 03:00:00 GMT  
 Simple task-not simple for Dummy, Help

Hi TARBABY,

Not sure what you want to do. Do you want the last
10 scores ? Or do you want to have the scores for
some date(s) ?
In your routine you are not priming your date field,
so it will always read the first ten records only, unless
this date field happens to have some value, which
will get you random results.
I think you want the last ten scores. If so:

     ROU:MemberNumber = PLA:MemberNumber
     CLEAR(ROU:Date,1)
     ......
     Loop until Access:Rounds.Previous()
       .....

With those two changes, you'll get the last 10 records.

HTH
Maarten



Sat, 09 Dec 2000 03:00:00 GMT  
 Simple task-not simple for Dummy, Help

Hi,

Quote:
> I have a routine written within the embedded code.  The routine is to open a
> file read the data based on a relationship with another file, process a loop to
> caluculate  an average, but only use the lastest (by date) records.  The key I
> am setting is a multi field key the contains a reference number, date, and
> score (the item to be averaged).  However, the program does not calculate
> correctly.  It takes the best of 5 of all scores, not best of 5 from only ten
> scores. Here is the code, any help is soooooooooooooooo greatly appreciated:

> FindAverage         routine

>   SET(PLA:KeyMemberNumber)
>   LOOP until Access:Players.Next()
>     clear(Rou:Record)
>     ROU:MemberNumber = PLA:MemberNumber
>     Counter# = 0
>     Tally$ = ''
>     count = 1
>     SET(ROU:RoundsKey, ROU:RoundsKey)
>     Loop until Access:Rounds.Next()
>       If Rou:MemberNumber <> PLA:MemberNumber or (Count > 10) then break.
>       My:Score = ROU:PointsMade
>       My:date = ROU:Date
>       Add(ScoreQ)
>       Counter# += 1
>       count += 1
>     END ! loop rounds
>     If Counter#
>       SORT(ScoreQ,-My:Score,-my:date)
>       case Counter#
>         of 1 to 2
>           EndScores# = 1
>         of 3 to 4
>           EndScores# = 2
>         of 5 to 6
>           EndScores# = 3
>         of 7 to 8
>           EndScores# = 4
>         else
>           EndScores# = 5
>       END ! case
>       LOOP J# = 1 TO EndScores#
>         GET(ScoreQ,j#)
>         Tally$ += My:Score
>     END         ! j loop
>       PLA:AveragePoints = Tally$ / EndScores#
>     END           !if counter
>     IF PLA:AVERAGEPOINTS < 15
>        PLA:AVERAGEPOINTS = 15
>     END           ! if under 15
>     Access:Players.Update()
>     FREE(ScoreQ)
>   END             ! main loop
>  POST(Event:CloseWindow)

>  exit

I think you should free the Score-queue before filling it. Part of the code should
then look like

    clear(Rou:Record)
    ROU:MemberNumber = PLA:MemberNumber
    Counter# = 0
    Tally$ = ''
    count = 1
    free(ScoreQ)
    SET(ROU:RoundsKey, ROU:RoundsKey)
    Loop until Access:Rounds.Next()
      If Rou:MemberNumber <> PLA:MemberNumber or (Count > 10) then break.
      .
      .
      .

Hope that helps.

Rainer Plischke
Just-EDV



Sat, 09 Dec 2000 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. A simple task: can anyone help me ?

2. simple tasking help

3. Simple task - big problem

4. Simple ABC task

5. C5 Simple/Hard Task!!

6. Simple Tasks!

7. !SIMPLE TASK:-) (PROJECT TREE)

8. SIMPLE TASK! ( Data Dictionary)

9. SIMPLE TASK!(Cut&Paste Highlighted Text)

10. Simple Task! (Creating dictionary)

11. Simple Task!

12. SIMPLE TASK

 

 
Powered by phpBB® Forum Software