Dividing by Zero
Posted: Sat Jan 28, 2012 7:42 pm
Question, hope it not a stupid one... I have a problem with my script for a program that has 3 check boxes, a field for the user to enter a number and a button to cycle through the amount of times the user entered. I wrote a "switch" to trigger actions until the count reaches "0", but my problem starts when the script attempts to calculate a percentage and list them in the appropriate fields. If on of the check boxes is selected it can calculate that percentage fine, but the script gives an error for the other two stating "execution error at line 50 (Operators /: divide by zero), char 15". What should I do here to fix this problem? I will attach the script below...
here is the problem area:
put (vTotal/vCorr)*100 into fld "correctNum"
put (vTotal/vCorrCue)*100 into fld "withCueNum"
put (vTotal/vincorrect)*100 into fld "incorrectNum"
here is the problem area:
put (vTotal/vCorr)*100 into fld "correctNum"
put (vTotal/vCorrCue)*100 into fld "withCueNum"
put (vTotal/vincorrect)*100 into fld "incorrectNum"
Code: Select all
on mouseUp
global vTotal
global vCorr
global vCorrCue
global vIncorrect
global vCustom
put fld "customField" into vCustom
switch vCustom > 0
case the hilite of button "correct"
add 1 to vCorr
set the hilite of button "correct" to false
set the hilite of button "correctCue" to false
set the hilite of button "incorrect" to false
break
case the hilite of button "correctCue"
add 1 to vCorrCue
set the hilite of button "correct" to false
set the hilite of button "correctCue" to false
set the hilite of button "incorrect" to false
break
case the hilite of button "incorrect"
add 1 to vIncorrect
set the hilite of button "correct" to false
set the hilite of button "correctCue" to false
set the hilite of button "incorrect" to false
break
default
end switch
if vCustom > 0 then
add 1 to vTotal
put vCustom -1 into vCustom
put vCustom into fld "customField"
set the label of me to "Next"
put (vTotal/vCorr)*100 into fld "correctNum"
put (vTotal/vCorrCue)*100 into fld "withCueNum"
put (vTotal/vincorrect)*100 into fld "incorrectNum"
else
set the label of me to "Start"
end if
end mouseUp