
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