--- loncom/homework/grades.pm	2007/10/17 10:48:20	1.461
+++ loncom/homework/grades.pm	2007/10/24 09:51:47	1.462
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.461 2007/10/17 10:48:20 foxr Exp $
+# $Id: grades.pm,v 1.462 2007/10/24 09:51:47 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -5383,20 +5383,22 @@ sub scantron_parse_scanline {
 
 		my $first_answer = $ansnum;
 		for (my $ans =0; $ans < $answers_needed; $ans++) {
-		    $record{"scantron.$ansnum.answer"} = '';
-		    $ans++;
+		    my $item = $first_answer+$ans;
+		    $record{"scantron.$item.answer"} = '';
 		}
 
 		my @ans=@array;
-		my $i=length($ans[0]);shift(@ans);
+		my $i=0;
+		my $increment = 0;
 		while ($#ans) {
-		    $i+=length($ans[0])+1;
-		    my $line   = $i/$$scantron_config{'Qlength'} + $first_answer;
+		    $i+=length($ans[0]) + $increment;
+		    my $line   = int($i/$$scantron_config{'Qlength'} + $first_answer);
 		    my $bubble = $i%$$scantron_config{'Qlength'};
-
 		    $record{"scantron.$line.answer"}.=$alphabet[$bubble];
 		    shift(@ans);
+		    $increment = 1;
 		}
+		$ansnum += $answers_needed;
 	    }
 	}
     }
@@ -6492,8 +6494,8 @@ sub scantron_bubble_selector {
 	if ($l != 0) {
 	    $r->print('<tr>');
 	}
+	my @selected = split(//,$lines[$l]);
 	for (my $i=0;$i<$max;$i++) {
-	    my @selected = split(//,$lines[$l]);
 	    $r->print("\n".'<td align="center">');
 	    if ($selected[0] eq $alphabet[$i]) { 
 		$r->print('X');