FileMaker除以零错误

时间:2013-11-18 02:09:01

标签: filemaker

我在结果表中有一个计算字段,它将根据学生提交的课堂作业,家庭作业,测验,项目和参与来计算课程作业。 “计算”字段的代码如下:

Sum (  Coursework_Results_Classwork::mark ) / If ( Sum ( Coursework_CR_Classwork::max_mark )  ≠ 0 ; Sum ( Coursework_CR_Classwork::max_mark ) - Sum ( Coursework_Results_Classwork::reduce_max ) ; 1 ) * Coursework_Weighting::classwork_w
+
Sum ( Coursework_Results_Homework::mark ) / If ( Sum ( Coursework_CR_Homework::max_mark ) ≠ 0 ; Sum ( Coursework_CR_Homework::max_mark ) - Sum ( Coursework_Results_Homework::reduce_max ) ; 1 ) * Coursework_Weighting::homework_w
+
Sum ( Coursework_Results_Quiz::mark ) / If ( Sum ( Coursework_CR_Quiz::max_mark ) ≠ 0 ;  Sum ( Coursework_CR_Quiz::max_mark ) - Sum ( Coursework_Results_Quiz::reduce_max ) ; 1 ) * Coursework_Weighting::quiz_w
+
Sum ( Coursework_Results_Project::mark ) / If ( Sum ( Coursework_CR_Project::max_mark ) ≠ 0  ; Sum ( Coursework_CR_Project::max_mark ) - Sum ( Coursework_Results_Project::reduce_max ) ; 1 ) * Coursework_Weighting::project_w
+
Sum ( Coursework_Results_Participation::mark ) / If ( Sum ( Coursework_CR_Participation::max_mark ) ≠ 0 ; Sum ( Coursework_CR_Participation::max_mark ) - Sum ( Coursework_Results_Participation::reduce_max ) ) * Coursework_Weighting::participation_w

代码背后的想法是这样的: 如果学生因有正当理由未提交课程作业,则不应受到处罚。因此,他的最大标记应相应调整。我使用reduce_max来减少他的最大可能分数。

我的错误是这样的: 如果特定类别(例如家庭作业)只有1个作业且学生没有提交有效理由(因此为空字段),则计算字段将具有division by zero error。我无法使用zero,因为zero在没有正当理由的情况下用于非提交。我怀疑这个错误发生在If ≠ 0条件测试中。空字段不被视为zero

有人可以帮帮我吗?感谢。

我修改了pft的答案以解决我的问题。该错误并非真正归因于空场。相反,当我使用reduce_max使得课程作业的最大值变为零时,就会发生这种情况。我的解决方案是:

Let ([
sumOfClasswork = Sum (  Coursework_Results_Classwork::mark );
sumOfHomework = Sum (  Coursework_Results_Homework::mark );
sumOfQuiz = Sum (  Coursework_Results_Quiz::mark );
sumOfProject = Sum (  Coursework_Results_Project::mark );
sumOfParticipation = Sum (  Coursework_Results_Participation::mark );

classworkMax = Sum ( Coursework_CR_Classwork::max_mark );
homeworkMax = Sum ( Coursework_CR_Homework::max_mark );
quizMax = Sum ( Coursework_CR_Quiz::max_mark );
projectMax = Sum ( Coursework_CR_Project::max_mark );
participationMax = Sum ( Coursework_CR_Participation::max_mark );

classworkReductions = Sum ( Coursework_Results_Classwork::reduce_max );
homeworkReductions = Sum ( Coursework_Results_Homework::reduce_max );
quizReductions = Sum ( Coursework_Results_Quiz::reduce_max );
projectReductions = Sum ( Coursework_Results_Project::reduce_max );
participationReductions = Sum ( Coursework_Results_Participation::reduce_max );

// if coursework maximum after reduction is zero, 1 is returned to avoid a division by zero error
classworkRedMax = If ( classworkMax - classworkReductions <> 0 ; classworkMax - classworkReductions ; 1 );
homeworkRedMax = If ( homeworkMax - homeworkReductions <> 0 ; homeworkMax - homeworkReductions ; 1 );
quizRedMax = If ( quizMax - quizReductions <> 0 ; quizMax - quizReductions ; 1 );
projectRedMax = If ( projectMax - projectReductions <> 0 ; projectMax - projectReductions ; 1 );
participationRedMax = If ( participationMax - participationReductions <> 0 ; participationMax - participationReductions ; 1 );

classworkWeight = Coursework_Weighting::classwork_w;
homeworkWeight = Coursework_Weighting::homework_w;
quizWeight = Coursework_Weighting::quiz_w;
projectWeight = Coursework_Weighting::project_w;
participationWeight = Coursework_Weighting::participation_w
];
// finally the computation of coursework ;)
sumOfClasswork / classworkRedMax * classworkWeight
+ 
sumOfHomework / homeworkRedMax * homeworkWeight
+
sumOfQuiz / quizRedMax * quizWeight
+
sumOfProject / projectRedMax * projectWeight
+
sumOfParticipation / participationRedMax * participationWeight
)

1 个答案:

答案 0 :(得分:2)

我相信IsEmpty功能可以帮到你。如果我理解你的意图,你可以使用这段代码:

Let ([
    sumOfMarks = Sum (  Coursework_Results_Classwork::mark );
    sumOfMaxs = Sum ( Coursework_CR_Classwork::max_mark );
    sumOfReductions = Sum ( Coursework_Results_Classwork::reduce_max );
    firstMax = Coursework_CR_Classwork::max_mark;
    theWeight = Coursework_Weighting::classwork_w
];
    Case (
       // The case where the student has at least one valid,
       // positively-scored assignment
       sumOfMaxs > 0 ; sumOfMarks / (sumOfMaxs - sumOfReductions) ;

       // The case where there is only one related record for max_mark
       // and it is empty
       IsEmpty ( firstMax ) ; 1

    ) * theWeight
)